JQuery jquery-1.7.1.min.js live() deprecated use on()

后端 未结 2 2058
小蘑菇
小蘑菇 2021-01-22 08:57

from jQuery website:

As of jQuery 1.7, the .live() method is deprecated. Use .on() to attach event handlers.

with version 1.7.1 i

2条回答
  •  伪装坚强ぢ
    2021-01-22 09:20

    Converting code from using .live to .on isn't just a case of replacing the calls to .live with .on calls. They accept different arguments, and are called on different selectors. For example, the old syntax:

    $('a').live('click', function () {});
    

    With .on:

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

    This syntax gives you greater control and flexibility.

    I would recommend reading the documentation: http://api.jquery.com/on/

    And for information on converting to .on from .live: http://api.jquery.com/live/

提交回复
热议问题