zoukankan      html  css  js  c++  java
  • 阻止事件冒泡

    <!doctype html>
    <html>
    <head>
        <title></title>
        <meta charset = "utf-8"/>
    </head>
    <style type="text/css">
    #grandpa{300px;height:300px;background:green;}
    #father{200px;height:200px;background:gray;}
    #self{100px;height:100px;background:pink;}
    </style>
    
    <script type="text/javascript">
    function self(evt){
     alert("我被打击了") 
      if(event&&event.stopPropagation){//非IE
            event.stopPropagation();
      }else{//IE
            window.event.cancelBubble=true;
      }
     
    }
    function father(){
      alert("爸爸被打击了") 
    }
    function grandpa(){
      alert("爷爷被打击了") 
    }
    
    </script>
    <body>
        <div id="grandpa" onclick="grandpa()">
            <div id="father" onclick="father()">
                <div id="self" onclick="self()">
                    我是最内层的哦;
                </div>
            </div>
        </div>
        
      
    </body>
    </html>
  • 相关阅读:
    ReentrantLock与synchronized的差别
    读TIJ -1 对象入门
    wikioi 2573 大顶堆与小顶堆并用
    开源 免费 java CMS
    UVA10972
    springboot5
    spring-boot4
    spring-boot3
    spring-boot2
    spring-boot1
  • 原文地址:https://www.cnblogs.com/ahu666/p/6838663.html
Copyright © 2011-2022 走看看