zoukankan      html  css  js  c++  java
  • js 阻止父级元素的事件向子级元素传递

    <html>
    <title></title>
    <head>
        <meta charset="utf-8">
        <style type="text/css">
            .divone{100px;height:100px;background:black;position: relative;cursor: pointer}
            .divchild{position: absolute;margin:10px;50px;height:50px;background:white;cursor: pointer}
        </style>
        <script type="text/javascript">
            function divone(){ 
                //这里是divone事件的代码 
                console.log('divone事件');
                stopPropagation();
            } 
            
            function divchild(){
                //这里是divchild事件的代码 
                console.log('divchild事件');
                stopPropagation();
            }

            function stopPropagation(e) {  
                e = e || window.event;  
                if(e.stopPropagation) { //W3C阻止冒泡方法  
                    e.stopPropagation();  
                } else {  
                    e.cancelBubble = true; //IE阻止冒泡方法  
                }  
            }
        </script>
    </head>
    <body>
        
        <div class="divone" onclick="divone(this)"> 
            
            <div class="divchild" onclick="divchild(this)"></div> 
            
        </div> 
     
    </body>
    </html>
  • 相关阅读:
    Redis学习六(java中使用redis)
    Redis学习五(新数据类型)
    Redis学习四(发布和订阅)
    Redis学习三(配置文件说明)
    Redis学习二(常用五大数据类型)
    Redis学习一(源码安装redis)
    RocketMq常见问题记录
    总结多种容器化技术对比
    关于Redis集群部署和持久化的相关问题
    配置Jenkins连接kubernetes的Pod Template模板
  • 原文地址:https://www.cnblogs.com/guangzhou11/p/13207663.html
Copyright © 2011-2022 走看看