• 事件冒泡例子


    <body>
      <div id="red" style="border: 1px solid #000;  400px; height: 400px;">
        <div id="blue" style="border: 1px solid #000;  300px; height: 300px;">
          <div
            id="pink"
            style="border: 1px solid #000;  200px; height: 200px;"
          ></div>
        </div>
      </div>
    </body>
    <script type="text/javascript">
      var red = document.getElementById("red");
      var blue = document.getElementById("blue");
      var pink = document.getElementById("pink");
      red.onclick = function (event) {
        red.style.backgroundColor =
          red.style.backgroundColor === "red" ? "" : "red";
        event.stopPropagation();
    
        // stop(event);
      };
      blue.onclick = function (event) {
        blue.style.backgroundColor = "blue";
        event.stopPropagation();
        // stop(event);
      };
      pink.onclick = function (event) {
        event.stopPropagation();
    
        pink.style.backgroundColor =
          pink.style.backgroundColor === "pink" ? "" : "pink";
    
        // stop(event);
      };
      function stop(event) {
        //阻止冒泡
        var evt = event || window.event;
        console.log("???", evt);
        if (evt.cancelBubble) {
          evt.cancelBubble = true;
        } else {
          evt.stopPropagation();
        }
      }
    </script>
  • 相关阅读:
    ADO之connection
    函数及自定义函数
    母版页
    XHTML5 与 HTML 4.01的差异
    三层架构的使用
    ExecuteNonQuery&& ExecuteQuery 区别
    常用数据结构的时间复杂度
    图像处理(卷积)作者太棒了
    C#中标准Dispose模式的实现
    计算机网络知识点
  • 原文地址:https://www.cnblogs.com/wilsunson/p/13405105.html
Copyright © 2020-2023  润新知