例如:
html:
在,js文件里有:
$(function(){
$('.a').click(function(){
alert('ok');
})
$('.b').click(function(){
$("").insertAfter($(this));
})
})
那么新的dom结构就是
而后面那个a点击的时候就不会触发$('.a').click事件
问:怎么让后面加载的'.a'能够触发那个click事件
Copyright 2014-2026 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号
因为你创建的新结构没有绑定事件,如果希望绑定的结构也有事件,你可以考虑把事件绑定到body,然后通过判断点击事件的节点是否有 calss=a,来加载相应的事件;
$('body').click(function(e){ var t = $(e.target); if(t.hasClass('a')){......} })