JS阻止冒泡事件

<!DOCTYPE html>
<html>
<head>
<title></title>
<style type="text/css">
#dv1{
500px;height: 500px;background: red;border: 1px solid;
}
#dv2{
400px;height: 400px;background: blue;border: 1px solid;
}
#dv3{
200px;height: 200px;background: yellow;border: 1px solid;
}
</style>
</head>
<body>
<div id ="dv1">
<div id ="dv2">
<div id ="dv3"></div>
</div>
</div>
<script type="text/javascript">
var b1=document.getElementById('dv1');
var b2=document.getElementById('dv2');
var b3=document.getElementById('dv3');
b1.onclick=function () {
alert(1);

// body...
}
function zuzhi(evt){
var e=evt||window.event
window.event? e.cancelBubble=true:e.stopPropagation();
}
b2.onclick=function () {
alert(2)
// body...
}
b3.onclick=function () {
alert(3);
zuzhi();
// body...
}
</script>
</body>
</html>

原文地址:https://www.cnblogs.com/a8497336/p/6033843.html