关于阻止冒泡的问题

jquery on委托事件里面加上阻止冒泡,不起作用。

原来的例子:

$(".allthree").on("click","li a",function(e){
   e.stopPropagation();//阻止冒泡
console.log(111);
})
$(document).click(function(){
console.log(222);
})

点击之后,还是会输出222;阻止冒泡不起作用

解决方法:

$(document).on("click",".allthree li a",function(e){
   e.stopPropagation();//阻止冒泡
console.log(111);
})
$(document).click(function(){
console.log(222);
})
原文地址:https://www.cnblogs.com/daiwenru/p/7254079.html