代码之家  ›  专栏  ›  技术社区  ›  ceving

如何在按钮中启用传播?

  •  0
  • ceving  · 技术社区  · 6 年前

    details 可以单击元素来打开和关闭它。但是当我把 元素转换为 button 细节

    有没有办法在按钮元素的后代中接收事件?

    function capture() {
      console.log ('capture: ', this);
    }
    
    document.getElementById("b").addEventListener('click', capture, true);
    document.getElementById("d").addEventListener('click', capture, true);
    <details>
      <summary>Hello World!</summary>
      Sed ut perspiciatis unde omnis iste natus error sit voluptatem accusantium doloremque
      laudantium, totam rem aperiam, eaque ipsa quae ab illo inventore veritatis et quasi
      architecto beatae vitae dicta sunt explicabo.
    </details>
    
    <button id="b">
      <details id="d">
        <summary>Hello World!</summary>
        Sed ut perspiciatis unde omnis iste natus error sit voluptatem accusantium doloremque
        laudantium, totam rem aperiam, eaque ipsa quae ab illo inventore veritatis et quasi
        architecto beatae vitae dicta sunt explicabo.
      </details>
    </button>
    0 回复  |  直到 6 年前
    推荐文章