zoukankan      html  css  js  c++  java
  • addEventListener中的第三个参数

    <!DOCTYPE html>
    <html>
        <head>
            <meta name="generator" content="HTML Tidy for HTML5 (experimental) for Windows https://github.com/w3c/tidy-html5/tree/c63cc39">
            <title></title>
        </head>

        <body>
            <div id="id1" style="200px; height:200px; position:absolute; top:100px; left:100px; background-color:blue; z-index:4">
                <div id="id2" style="200px; height:200px; position:absolute; top:20px; left:70px; background-color:green; z-index:1"></div>
            </div>
        <p>addEventListener中的第三个参数是useCapture, 一个bool类型。当为false时为bubbling获取(由里向外),true为capture方式(由外向里)。</p>
        
            <script>
        /*case1 print id2,id1*/
            document.getElementById("id1").addEventListener('click', function() { console.log('id1');}, false);  
            document.getElementById("id2").addEventListener('click', function() { console.log('id2');}, false);  
        /*case2 print id2,id1*/
            document.getElementById("id1").addEventListener('click', function() { console.log('id1');}, true);  
            document.getElementById("id2").addEventListener('click', function() { console.log('id2');}, false);  
        /*case3 print id1,id2*/
            document.getElementById("id1").addEventListener('click', function() { console.log('id1');}, true);  
            document.getElementById("id2").addEventListener('click', function() { console.log('id2');}, false);  
        /*case4 print id1,id2*/
            document.getElementById("id1").addEventListener('click', function() { console.log('id1');}, true);  
            document.getElementById("id2").addEventListener('click', function() { console.log('id2');}, true);  
            </script>
        </body>
    </html>

  • 相关阅读:
    OpenLayer 3 鹰眼控件和全屏显示
    OpenLayer 3 鼠标位置坐标显示控件
    Openlayer 3 图层列表控件(自定义)
    OpenLayers 3 的地图基本操作
    小米范工具系列之十四:小米范网站批量爬虫工具
    ruby所有版本下载地址
    常用代码块:使用时间生成数据库文件名
    收集些常用的正则--以后慢慢添加
    小米范工具系列最新下载地址
    小米范工具系列之十三:小米范验证码登录爆破工具
  • 原文地址:https://www.cnblogs.com/mguo/p/3030055.html
Copyright © 2011-2022 走看看