<!DOCTYPE html>
<html>
<head>
<title></title>
</head>
<body>
<div style="width: 400px;height: 400px;background-color: #678678;font:3em bold;" id="outDiv">
out
<div style="width: 200px;height: 200px;margin: 50px;background-color: #eaceac;font:1em bold;" id="inDiv">in</div>
</div>
<script>
document.getElementById("inDiv").addEventListener('click',function(e){
alert('in');
e.stopPropagation();//终止事件冒泡
},false);
document.getElementById("outDiv").addEventListener('click',function(e){
alert('out');
},false);
</script>
</body>
</html>
点击里面div或外面div的事件冒泡问题
最新推荐文章于 2024-06-09 00:06:15 发布