jquery: on vs live

前端 未结 3 681
隐瞒了意图╮
隐瞒了意图╮ 2020-12-06 22:57

I am curious why when I replace .live() with .on() my events don\'t work after inserting AJAX\'s response via html() method. Assume I

3条回答
  •  南笙
    南笙 (楼主)
    2020-12-06 23:37

    It is indeed a replacement for .delegate and .live, but you have to pass in some additional parameters:

    var container = $('.a').on('click', '.alert-link', function() {
        alert('abc');
        return false;
    }).on('click', '.ajax-update', function() {
        // something that uses AJAX to update .a, like:
        container.load('some-url');
        return false;
    });
    

    For more information, see the documentation.

提交回复
热议问题