美文网首页
【前端】冒泡事件和阻止冒泡

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

作者: 歌声缓缓 | 来源:发表于2021-03-04 16:54 被阅读0次

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

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

相关文章

网友评论

      本文标题:【前端】冒泡事件和阻止冒泡

      本文链接:https://www.haomeiwen.com/subject/yjlufltx.html