2012-09-19 68 views
0

我正在使用jquery樣板(),並且無法通過我的不同方法訪問我的選項。jQuery Plugin Boilerplate

例如

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' 
    } 
} 

我想在我的輸入法,但沒有成功進入我的選擇。

有人可以幫我找出原因嗎?

感謝

回答

2

this在處理程序是你所點擊的元素。

如果你想保留原來的this,請致電jQuery.proxy

+0

有人可以舉例說明如何在Boilerplate中使用JQuery Proxy。我已經諮詢過JQuery文檔,但無法將其應用於此模式。 謝謝 –

+0

@JamesHowell:你不明白什麼? – SLaks