CommandEvent: command 屬性

可用性有限

此特性不是基線特性,因為它在一些最廣泛使用的瀏覽器中不起作用。

CommandEvent 介面的 command 只讀屬性返回一個字串,其中包含事件分派時 command 屬性的值。

字串。

示例

在下面的簡單示例中,我們設定了一個事件監聽器來監聽“show-modal”命令

js
document.body.addEventListener(
  "command",
  (event) => {
    const theAction = event.command;

    if (theAction === "show-modal") {
      console.log("Showing modal dialog");
    }
  },
  { capture: true },
);

規範

規範
HTML
# dom-commandevent-command

瀏覽器相容性

另見