zoukankan      html  css  js  c++  java
  • js

      

      想要阻止点击 #content 区域时触发a事件,需要在 #content 区域内加入阻止事件冒泡的代码,具体代码如下:

    <div id="box" onclick="a()"> 
        <div id=content> 
        </div> 
    </div> 

      

      #box 包括 #content ,当点击 #box 区域任何位置时(包括 #content ),都会触发a事件。想要阻止点击 #content 区域时触发a事件,需要在 #content 区域内加入阻止事件冒泡的代码。 代码如下:

    <div id="box" onclick="a()"> 
        <div id="content" onclick="stopBubble(this.id)"> 
        </div> 
    </div>
    function a(){ 
    //这里是a事件的代码 
    } 
    function stopBubble(e) { 
        if (e && e.stopPropagation) {//非IE浏览器 
          e.stopPropagation(); 
        } 
        else {//IE浏览器 
            window.event.cancelBubble = true; 
        } 
    } 
  • 相关阅读:
    玩游戏(dfs)
    Find them, Catch them(并查集)
    Shredding Company(dfs)
    Sudoku(dfs)
    Network Saboteur(dfs)
    棋盘问题(dfs)
    Curling 2.0(dfs)
    A Knight's Journey(dfs)
    15. 3Sum
    12. Integer to Roman
  • 原文地址:https://www.cnblogs.com/lulin1/p/7485797.html
Copyright © 2011-2022 走看看