【问题标题】:jQuery Plugin BoilerplatejQuery 插件样板
【发布时间】:2012-09-19 23:24:42
【问题描述】:

我正在使用 jquery 样板 (),并且无法通过我的不同方法访问我的选项。

例如

Plugin.prototype = {
    init: function()
    {
        console.log(this.options); // This output my options

        $(this.element).on('mouseenter', this.enter);
        $(this.element).on('mouseleave', this.leave);
        $(this.element).on('click', this.click);
    },
    enter: function(e)
    {
        console.log(this.options); // This output 'undefined'
    }
}

我试图在我的 enter 方法中访问我的选项,但没有成功。

谁能帮我找出原因?

谢谢

【问题讨论】:

    标签: jquery methods boilerplate


    【解决方案1】:

    处理程序中的this 是您单击的元素。

    如果您想保留原来的this,请致电jQuery.proxy

    【讨论】:

    • 有人可以举例说明如何在样板中使用 JQuery 代理。我已经查阅了 JQuery 文档,但无法将其应用于此模式。谢谢
    • @JamesHowell:你不明白什么?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-05-10
    • 2011-06-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多