js事件冒泡

来源:互联网 发布:济南java工资线 编辑:程序博客网 时间:2024/06/06 09:35

1、在内部的点击事件的方法中加入event.stopPropagation(); 可以阻止外部点击事件。

eg:

<div id='outSide' onclick='clickOutSide()'>
    <span>look at here</span>
<div id='inSide' onclick='clickInSide()'>
 <span> what will happen</span>
</div>
</div>


<script>
function clickOutSide(){
alert("you are just clicking the outside div");
}
function clickInSide(){

event.stopPropagation();
alert("you are just want to click the inside div");
}
</script>

原创粉丝点击