1
我是新來的jQuery和我建立一個自定義插件,它看起來是這樣的(僞代碼):jQuery插件:如何訪問從輔助函數應用插件的元素?
jQuery.fn.myPlugin = function(options)
{
var defaults = {
interval : 5 * 1000
};
var interval_handler = setInterval(function() { update(); }, interval);
var opts = $.extend(defaults, options);
return this.each(function(){
$(this).bind(event, stuff);
});
function update()
{
if (condition == true)
{
clearInterval(interval);
// unbind() foreach element the plugin has used
}
}
}
我的問題是:
如何可以訪問所有的插件有元素用於從update()
功能return this.each(...)
?
此外,是我使用插件內功能正確的方式嗎?我不知道該怎麼做,所以我只是嘗試了一下而已。