且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

使用jQuery自动将事件处理程序添加到新创建的元素中

更新时间:2023-11-03 20:14:22

例如,使用on()方法在公共父元素上使用事件委托(假设您使用的是jQuery 1.7.x +)

Use event delegation on a common parent element using on() method (assuming you're using jQuery 1.7.x +), e.g.

$(function() {
    $('body').on('mouseenter', '.bubbleItemOff', function(e) 
    {
     ...
    }
}

如果您使用的是旧版本,请改用delegate().用.bubbleItemOff

if you're using an older version use delegate() instead. Change body with the first common parent element of .bubbleItemOff