JQuery live or something similar with .change()?

橙三吉。 提交于 2020-01-02 05:43:09

问题


I want to do this: http://docs.jquery.com/Events/live#typefn

Only .live() doesn't support the change event- any ideas for work arounds?

Need to bind a function to some on-the-fly DOM elements, but not until change.


回答1:


Note: jQuery 1.4 now supports the live function for all normal events. It didn't work with IE8 until recently, but I believe this is fixed with jQuery 1.4.2. See this resolved jQuery ticket: IE8 DOES NOT SUPPORT THE CHANGE EVENT WHILE USING LIVE




回答2:


LiveQuery plugin supports all events.




回答3:


Oh that wasn't so bad, i just wrapped it in a live on click event and it worked just fine.


$("#foo").live("click", function(){
  $('.fu').change(function(){
    blah blah blah
  });
});



回答4:


Ok, after Funka's comments on my first attempt at answering my own question, I now have this:


$('.foo').change(function test(){
  $(fu).prependTo("#some-div").bind("change", test)
  $(this).unbind("change",test)
};

Which will bind the function to each element as it is created, and unbind it from the one created before it. This solves my problem UI-wise, but I'm obvs novice so am really open to learning if I am missing something again! ;)




回答5:


Before there was .live() in jQuery 1.3, I had great success with Arial Flesler's "listen" plugin.

http://flesler.blogspot.com/search/label/jQuery.Listen

I believe you should be able to do this on the change event with this plugin.



来源:https://stackoverflow.com/questions/1343985/jquery-live-or-something-similar-with-change

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