callback after jQuery.trigger() function

后端 未结 4 710
遥遥无期
遥遥无期 2021-01-12 08:00

i have got a little problem here. I have to trigger an event which contains $.post() to load a form and assign it to a DOM. After this is done, i have edit the fields of the

4条回答
  •  既然无缘
    2021-01-12 08:34

    .live has been deprecated in jQuery since v1.7, and has been removed in v1.9.

    You should replace it with .on().

    .on has 2 signatures for binding elements, whereas .live only had 1.

    If the element exists at the time you are binding, you do it like this:

    $('.element').on('click', function(){
      .......
    });
    

    You can even use the shorthand:

    $('.element').click(function(){
      .........
    });
    

    If the element does not exist at the time, or new ones will be added (which is what .live was normally used for), you need to use "event delegation":

    $(document).on('click', '.element', function(){
      ........
    });
    

    NOTE: You want to bind to the closest static element, not always document.

    In the meantime, the jQuery Migrate plugin can be used to restore the .live() functionality if you upgrade your jQuery to the newest version.

提交回复
热议问题