zoukankan      html  css  js  c++  java
  • 使用cancelBubble竟然可以阻止所有浏览器的冒泡?

    以前一直以为cancelBubble是IE8及以下的专属,今天做一个测试的时候意外发现了所有浏览器都支持,便提出来希望有哪位解释下。

    1.使用原生js在FF下和chrome下两种方法都可以阻止冒泡

    document.getElementById("wq").addEventListener("click",function(e){
        console.log('wq');
      },false);
      document.getElementById("we").addEventListener("click",function(e){
        console.log(e);
        // e.stopPropagation();
        e.cancelBubble = true;
      },false);

    2.使用jquery两种方法也都可以阻止冒泡

    <div id="wq">
          <span  id="we">click</span>
    </div>
    <script type="text/javascript" src="jquery-1.11.0.min.js"></script>
    <script type="text/javascript">
      $("#wq").on("click",function(){
        console.log("wq");
      });
      $("#we").on("click",function(e){
        console.log(e);
        // e.stopPropagation();
        e.originalEvent.cancelBubble = true;
      })
    </script>
  • 相关阅读:
    Linux软件安装
    虚拟地址和物理地址
    python 读写txt文件
    python 浮点数保留几位小数
    Contiki源码结构
    Contiki Rtimer 模块
    Contiki Ctimer模块
    Contiki Etimer 模块
    Contiki Timer & Stimer 模块
    Contiki clock模块
  • 原文地址:https://www.cnblogs.com/zhaodawei/p/4511694.html
Copyright © 2011-2022 走看看