码迷,mamicode.com
首页 > 其他好文 > 详细

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

时间:2019-04-04 17:33:12      阅读:205      评论:0      收藏:0      [点我收藏+]

标签:type   query   div   https   col   pre   nbsp   min   fun   

<!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>

 

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

标签:type   query   div   https   col   pre   nbsp   min   fun   

原文地址:https://www.cnblogs.com/jinsuo/p/10655824.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!