jQuery插件:如何从辅助功能访问应用了插件的元素? [英] jQuery plugin: How to access elements where plugin was applied from secondary function?
本文介绍了jQuery插件:如何从辅助功能访问应用了插件的元素?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我是jQuery的新手,正在构建一个自定义插件,它看起来像这样(伪代码):
I am new to jQuery and I am building a custom plugin, it looks something like this (pseudo-code):
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(...)
上使用的所有元素?
How can access all the elements the plugin has used on return this.each(...)
from the update( )
function?
此外,即时消息在插件中使用函数的方式是否正确?我不知道该怎么做,所以我尝试了一下,就行了.
推荐答案
您需要将其放在变量中:
You need to put it in a variable:
var elements = this;
这篇关于jQuery插件:如何从辅助功能访问应用了插件的元素?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文