<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>取消冒泡事件</title>
</head>
<style>
.div1 {
width: 300px;
height: 300px;
background: red;
}
.div2 {
width: 100px;
height: 100px;
background: yellow;
}
</style>
<body>
<div class="div1" id="div1">
<div class="div2" id="div2"></div>
</div>
</body>
<script>
div1.onclick = function(e) {
alert('div1');
}
div2.onclick = function() {
var e = window.event || e;
if (e.stopPropagation) {
e.stopPropagation();
} else {
e.cancleBubble = true;
}
alert('div2');
}
</script>
</html>
JavaScript——取消冒泡事件
最新推荐文章于 2021-08-09 18:26:36 发布