如何获取 jQuery 插件附加的元素?
How to get the element that jQuery plugin is attached?
我正在使用 jquery 插件。有没有办法从插件的函数中获取插件附加的元素?
我尝试了 this
、$(this)
。但是 none 他们的工作。
$('.myelement').plugin({
something: function(){
//in here I want to access $('.myelement)
}
});
看起来插件正在将该信息公开给回调方法。如果您正在处理多个元素,一种解决方法是遍历元素列表,然后使用可在回调中使用的本地引用为每个元素调用插件
$('selector').each(function() {
var $this = $(this);
$this.plugin({
something: function() { //$this
}
});
})
我正在使用 jquery 插件。有没有办法从插件的函数中获取插件附加的元素?
我尝试了 this
、$(this)
。但是 none 他们的工作。
$('.myelement').plugin({
something: function(){
//in here I want to access $('.myelement)
}
});
看起来插件正在将该信息公开给回调方法。如果您正在处理多个元素,一种解决方法是遍历元素列表,然后使用可在回调中使用的本地引用为每个元素调用插件
$('selector').each(function() {
var $this = $(this);
$this.plugin({
something: function() { //$this
}
});
})