CommandEvent:CommandEvent() 构造函数
Baseline
2025
Newly available
Since December 2025, this feature works across the latest devices and browser versions. This feature might not work in older devices or browsers.
CommandEvent() 构造函数用于创建一个新的 CommandEvent 对象。
语法
js
new CommandEvent(type)
new CommandEvent(type, options)
参数
type-
表示事件名称的字符串。区分大小写,浏览器会将其设置为
command。 options可选-
一个对象,除
Event()中定义的属性外,还可以包含下列属性:source可选-
一个
HTMLButtonElement,表示触发该事件的按钮。虽然可以使用任意元素作为来源,但建议仅使用按钮以避免意外行为。 command可选-
一个字符串,表示受控元素应执行的命令。手动实例化
CommandEvent时可以使用任意字符串,但建议使用内置名称或以两个连字符(--)为前缀,以确保向前兼容。
返回值
新的 CommandEvent 对象。