冒泡事件:点击盒子的方法,外层盒子的方法执行了
外层盒子是handle0方法 ;
里层盒子是 handle 方法
点击紫色盒子,红色盒子的方法执行了

<body>
<div id="box" onclick="handle0()">
<button type="button" onclick="handle()"></button>
</div>
</body>
<style type="text/css">
#box{
width: 300px;
height: 300px;
background-color:red;
}
button{
width: 100px;
height: 100px;
background-color: purple;
}
</style>
<script type="text/javascript">
function handle0(){
console.log("handle0")
}
function handle(){
//event.stopPropagation();
//event.preventDefault();
}
</script>
网友评论