此页面由社区从英文翻译而来。了解更多并加入 MDN Web Docs 社区。

View in English Always switch to English

CommandEvent:command 属性

Limited availability

This feature is not Baseline because it does not work in some of the most widely-used browsers.

CommandEvent 接口的只读属性 command 返回一个表示派发该事件的元素的 command 属性值的字符串。

字符串。

示例

在下面的简单示例中,我们设置了一个事件监听器来监听“show-modal”命令:

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

    if (theAction === "show-modal") {
      console.log("展示模态对话框");
    }
  },
  { capture: true },
);

规范

Specification
HTML
# dom-commandevent-command

浏览器兼容性

参见