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

View in English Always switch to English

CommandEvent:CommandEvent() 构造函数

Limited availability

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

CommandEvent() 构造函数用于创建一个新的 CommandEvent 对象。

语法

js
new CommandEvent(type)
new CommandEvent(type, options)

参数

type

表示事件名称的字符串。区分大小写,浏览器会将其设置为 command

options 可选

一个对象,Event() 中定义的属性外,还可以包含下列属性:

source 可选

一个 HTMLButtonElement,表示触发该事件的按钮。虽然可以使用任意元素作为来源,但建议仅使用按钮以避免意外行为。

command 可选

一个字符串,表示受控元素应执行的命令。手动实例化 CommandEvent 时可以使用任意字符串,但建议使用内置名称或以两个连字符(--)为前缀,以确保向前兼容。

返回值

新的 CommandEvent 对象。

规范

This feature does not appear to be defined in any specification.

浏览器兼容性

参见