html 点击子元素事件而不触发父元素的点击事件

阻止冒泡事件即可

//jquery
$("#btn").click(function(event){
    event.stopPropagation();//阻止事件冒泡即可
});

//js
document.getElementById("btn").onclick=function(event){
    event.stopPropagation();//阻止事件冒泡即可
}

猜你喜欢

转载自www.cnblogs.com/dch0/p/12091661.html