• Javascript 事件冒泡


    <!DOCTYPE html>
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
        <title></title>
    </head>
    <body>
        <div>
            <span></span>
            <ul>
                <li>nextSibling</li>
                <li>nextSibling</li>
                <li>nextSibling</li>
                <li>nextSibling</li>
                <li>nextSibling</li>
            </ul>
        </div>
        <script type="text/javascript">
            window.onload = function () {
    
            };
            function next(ele) {
                if (typeof ele.nextElementSibling == 'object') {
                    return ele.nextElementSibling;
                }
                var n = ele.nextSibling;
                while (n) {
                    if (n.nodeType == 1) {
                        return n;
                    }
                    n = n.nextSibling;
                }
                return n;
            }
            function fn(e) {
                e = e || window.event;
                if (e.stopPropagation) {
                    e.stopPropagation();
                } else {
                    e.cancelBubble = true;
                }
    
                if (e.stopPropagation()) {
                    e.stopPropagation();//标准浏览器阻止默认方式
                } else {
                    e.returnValue = false;//IE的组织默认行为
                }
            }
    
    
    
            function fn2() {
                alert(this.nodeName);
            }
            var ele = document.getElementsByTagName('li');
            for (var i = 0; i < ele.length; i++) {
                ele.item(i).addEventListener('click', fn2, false);
            }
    
    
            document.body.addEventListener("click", fn2, false);
    
            document.body.addEventListener('click', fn, true);
    
            document.addEventListener('click', fn, true);
    
            //内到外 冒泡 IE支持
            //外到内 捕获 IE不支持
        </script>
    </body>
    </html>
    

      

  • 相关阅读:
    APMServ5.2.6 无法启动Apache的一个问题
    【转】流媒体技术笔记(视频编码相关)
    用APMServ一键快速搭建Apache+PHP+MySQL+Nginx+Memcached+ASP运行平台
    java swing 基础
    python class 类
    python 经验
    python 导入(转)
    kernel ipv4/ip_output.c
    python+正则表达式(转)
    Eclipse中如何快速添加、删除jar包
  • 原文地址:https://www.cnblogs.com/alphafly/p/4699396.html
Copyright © 2020-2023  润新知