Event:target 屬性

Event:target 屬性

相關聯的 EventTarget。

範例

event.target 屬性可用於實作事件委派。

js// 建立一個列表

const ul = document.createElement("ul");

document.body.appendChild(ul);

const li1 = document.createElement("li");

const li2 = document.createElement("li");

ul.appendChild(li1);

ul.appendChild(li2);

function hide(evt) {

// evt.target 指的是被點擊的

  • 元素

    // 這與 evt.currentTarget 不同,在此上下文中的 currentTarget 指的是父層

      evt.target.style.visibility = "hidden";

      }

      // 將監聽器附加到列表

      // 當每個

    • 被點擊時,它都會觸發

      ul.addEventListener("click", hide);

      規範

      Specification

      DOM# ref-for-dom-event-target③

      瀏覽器相容性

      參見

      學習:事件冒泡

      Help improve MDN

      Was this page helpful to you?

      Yes

      No

      Learn how to contribute

      This page was last modified on 2026年3月3日 by MDN contributors.

      View this page on GitHub • Report a problem with this content

  • 相关推荐

    完整品牌营销策划方案怎么做?一文讲透
    香港物流货运公司排名(香港物流公司有哪些)
    网站制作公司哪家好?2025最新十大网站建设公司口碑推荐