阻止时间冒泡 -event.stopPropagation();

<!DOCTYPE html>
<html>
<head>
<script src="https://cdn.staticfile.org/jquery/1.10.2/jquery.min.js">
</script>
<script>
$(document).ready(function(){
 
  $("p").click(function(event){
    alert("The p element was clicked.");
  });
  $("div").click(function(){
    alert("The div element was clicked.");
       $("span").click(function(event){
        event.stopPropagation();  //阻止冒泡
        alert("The span element was clicked.");
      });
  });
});
</script>
</head>
<body>

<div style="height:100px;width:500px;padding:10px;border:1px solid blue;background-color:lightblue;">
ccc
<p style="background-color:pink">bbbb <br>
    <span style="background-color:orange">ccccc</span>
    </p>
</div>


</body>
</html>

 

posted @ 2019-04-04 16:57  Jinsuo  阅读(205)  评论(0编辑  收藏  举报