zoukankan      html  css  js  c++  java
  • [HTML 5] stopPropagation & stopImmediatePropagation

    const app = document.getElementById('app');
    app.innerHTML = `
      <h1>JavaScript DOM</h1>
      <div class="one">
        <div class="two">
          <button type="button" class="three">
            Click Me
          </button>
        </div>
      </div>
    `;
    
    const one = document.querySelector('.one');
    const two = document.querySelector('.two');
    const three = document.querySelector('.three');
    
    function handleClick(event) {
      event.stopPropagation();
      // event.stopImmediatePropagation();
      console.log(event.target);
    }
    
    one.addEventListener('click', handleClick);
    two.addEventListener('click', handleClick);
    three.addEventListener('click', handleClick);
    
    three.addEventListener('click', event => console.log(event), { capture: true });
    

      

    When use 'stopPropagation', the code:

    three.addEventListener('click', event => console.log(event), { capture: true });

    will still running.

    But when use 'stopImmediatePropagtion', that line of code will not run any more

  • 相关阅读:
    针对性博文
    spring事务
    Redis_主从模式_哨兵模式_Cluster集群模式
    Redis AOF、RDB持久化
    Redis 高可用分布式集群
    Redis 基础
    Oracle优化学习
    Mysql:索引实战
    Mysql:性能优化
    js 二维数组定义
  • 原文地址:https://www.cnblogs.com/Answer1215/p/12775100.html
Copyright © 2011-2022 走看看