我在1.4中创建了自己的jQuery插件,现在我需要少量帮助。

$.etrade = function()
{

}


我需要,所以我可以构建这样的代码

$.etrade = function()
{
    this.var = 'setting';

    this.subfunction = function()
    {
    };
}


当我从插件中获取功能时,我需要像这样使用它:

$.etrade.var = '5';
$.etrade.subfunction();


有人知道我的意思吗?以及如何解决这个问题? :)

最佳答案

听起来您想将普通的旧对象分配给$.etrade,而不是function。像这样:

$.etrade = {
    variable: 'setting',
    otherVariable: 'something else',
    subfunction: function () { /* do stuff here */ },
    anotherSubFunction: function () { /* do other stuff here */ }
}


就是说,我不确定这是否符合jQuery插件的资格,因为您似乎只是将临时属性添加到jQuery上。

另外:根据示例,您不能使用var,因为它是JavaScript中的关键字。

07-24 09:50
查看更多