Invoker Commands API
CommandEvent 接口的只读属性 command 返回一个表示派发该事件的元素的 HTMLButtonElement.command 属性值的字符串。
值
字符串。
示例
在下面的简单示例中,我们设置了一个事件监听器来监听“show-modal”命令:
document.body.addEventListener(
"command",
(event) => {
const theAction = event.command;
if (theAction === "show-modal") {
console.log("展示模态对话框");
}
},
{ capture: true },
);
规范
浏览器兼容性
参见
- Invoker Commands API
- HTMLButtonElement.command
- HTMLButtonElement.commandForElement
来源:MDN Web Docs / Mozilla 贡献者 · 作者与贡献记录 · CC BY-SA 2.5。离线整理了版式、链接和媒体显示。
