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

浏览器兼容性

另见