Div嵌套防止穿透事件

来源:互联网 发布:网络捕鱼游戏随机算法 编辑:程序博客网 时间:2024/05/16 18:54

轉自http://qiaolevip.iteye.com/blog/2087911

  1. <div style="width:100px; height:100px; border:1px solid #000" id="x">  
  2. <div style="width:50px; height:50px; margin:0 auto; border:1px solid #ccc" id="y"></div>  
  3. </div>  
  4. <script type="text/javascript">  
  5. document.getElementById("x").onclick=function(e)  
  6. {  
  7.     alert("x")  
  8.     e = e || window.event;  
  9.   if (e.stopPropagation )  
  10.         e.stopPropagation();  
  11.   else  
  12.         e.cancelBubble = true;  
  13.   
  14.   
  15. }  
  16. document.getElementById("y").onclick=function(e)  
  17. {  
  18.     alert("y")  
  19.    e = e || window.event;  
  20.   if (e.stopPropagation )  
  21.         e.stopPropagation();  
  22.   else  
  23.         e.cancelBubble = true;  
  24. }  
  25. </script>  

0 0