JQuery 'on' vs. 'live'

后端 未结 2 794
北海茫月
北海茫月 2020-12-18 08:51

I have a scenario where JQuery \'on\' & \'live\' do not perform the same. Perhaps someone can point out why. I am using JQuery 1.7.2 with my project and in this build,

2条回答
  •  一向
    一向 (楼主)
    2020-12-18 09:31

    One does not simply replace .live with .on.

    $("a.listajax").live('click', function(e))
    

    Is equivalent to:

    $(document).on('click', 'a.listajax', function(e))
    

    Important

    If there's a common ancestor for all your .listajax anchors that will not be removed from the DOM, you should use that (the deepest one possible) instead of document; this will improve performance.

提交回复
热议问题