我的jQuery插件事件未在多个元素上触发 [英] My jQuery plugin events not firing on multiple elements
本文介绍了我的jQuery插件事件未在多个元素上触发的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我写了一个jQuery插件来过滤选择列表选项.它在 one 列表上很好用,但在更多元素上却不起作用: http://jsfiddle. net/vgXPh/4/
I wrote a jQuery plugin to filter select list options. It works great on one list, but not on more elements: http://jsfiddle.net/vgXPh/4/
$("select.filter").listFilter(); // doesn't work
$("select.filter:first").listFilter(); // works
我看不到任何可能将其弄乱的全局变量.我是否正确调用绑定事件? JSLint没有抱怨.我在做什么错了?
I don't see any global variables that could be messing it up. Am I calling my bind events correctly? JSLint doesn't complain. What am I doing wrong?
推荐答案
您可能应该用this.each()
包围代码,如下所示:
You should probably surround your code with this.each()
, like this:
$.fn.listFilter = function() {
this.each(function() {
(...)
});
return this;
};
这篇关于我的jQuery插件事件未在多个元素上触发的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文