My jQuery plugin events not firing on multiple elements

允我心安 提交于 2019-12-24 18:55:23

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!