关于js中的事件问题?
橱窗的光
橱窗的光 2017-02-27 09:48:16
0
2
696
<!DOCTYPE html><html lang="en"><head>
    <meta charset="UTF-8">
    <title>Document</title>
    <style type="text/css">
        #out{           
          width: 500px;           
          height: 500px;            
          background: red;            
          position: relative;        
        }
        #in{            
            width: 200px;            
            height: 200px;            
            background: green;            
            position: absolute;        
       }
    </style>
    </head>
    <body>
    <div id="out">
        <div id="in"></div>
    </div>
    <script type="text/javascript">
        var out = document.getElementById("out");        
        var i = document.getElementById("in");
        out.addEventListener('click',a,true);
        i.addEventListener('click',b,false);        
        function a(){
            out.style.backgroundColor = 'black'; 
        }        function b(){
            i.style.backgroundColor = 'blue'; 
        }    
    </script>
    </body>
    </html>

在这段代码中为何点击子元素后父元素也会变色呢?在子元素上已经设置了阻止事件捕获啊?

橱窗的光
橱窗的光

熱門教學
更多>
最新下載
更多>
網站特效
網站源碼
網站素材
前端模板
關於我們 免責聲明 Sitemap
PHP中文網:公益線上PHP培訓,幫助PHP學習者快速成長!