【前端】冒泡事件和阻止冒泡

冒泡事件:点击盒子的方法,外层盒子的方法执行了

外层盒子是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>

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容