JS冒泡事件極其阻止方法

    <div onclick="a()">
     <div onclick="b()">
      <a id="a" href="" onclick="c()">點擊我</a>
     </div>
    </div>瀏覽器

當點擊「點擊我」按鈕的時候,會依次執行 方法 c(),b(),a()方法 這就屬於冒泡事件事件

阻止方法:io

      function c(){
           if(window.event){
                alert("IE")
                window.event.cancelBubble=true;    //阻止IE瀏覽器
           }else{
                alert("not IE")
                event.stopPropagation();   //阻止其餘瀏覽器   
           }event

      }function

相關文章
相關標籤/搜索