阻止冒泡

阻止冒泡

当页面中出现某个父元素点击显示,然后子元素点击隐藏父元素时,子元素执行事件时会自动传递给父元素,相当于子元素点击隐藏父元素,但是传递给父元素点击又显示,从而使效果无法正常

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
function stopPropagation(e) {
e = window.event || e;
if (document.all) {
e.cancelBubble = true;
} else {
e.stopPropagation();
}

}
$('.sub_colse').on("click", function (e) {
stopPropagation(e)
console.log(11)
$(this).parent().hide()
$('.sub_box').hide()
})

阻止冒泡
https://huangzunxue998.top/2023/04/28/阻止冒泡/
Author
黄dada
Posted on
April 28, 2023
Licensed under