问题
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
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?
回答1:
You should probably surround your code with this.each()
, like this:
$.fn.listFilter = function() {
this.each(function() {
(...)
});
return this;
};
来源:https://stackoverflow.com/questions/4500298/my-jquery-plugin-events-not-firing-on-multiple-elements