0

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メソッドのオプションにアクセスしようとしていますが、成功しません。

誰かが私が理由を理解するのを手伝ってくれる?

ありがとう

4

1 に答える 1

2

thisハンドラーには、クリックした要素があります。

元のを保持したい場合は、 jQuery.proxythisを呼び出します。

于 2012-09-19T23:27:43.827 に答える