Skip to content

Commit a490391

Browse files
xyy94813yin1999
andauthored
[zh-cn]: translate CommandEvent constructor (#30595)
Co-authored-by: A1lo <[email protected]>
1 parent 5b58747 commit a490391

File tree

1 file changed

+47
-0
lines changed
  • files/zh-cn/web/api/commandevent/commandevent

1 file changed

+47
-0
lines changed
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
---
2+
title: CommandEvent:CommandEvent() 构造函数
3+
slug: Web/API/CommandEvent/CommandEvent
4+
l10n:
5+
sourceCommit: 66ca26b10d8a8d7c8c287728cd60108b65a1f331
6+
---
7+
8+
{{APIRef("Invoker Commands API")}}
9+
10+
**`CommandEvent()`** 构造函数用于创建一个新的 {{domxref("CommandEvent")}} 对象。
11+
12+
## 语法
13+
14+
```js-nolint
15+
new CommandEvent(type)
16+
new CommandEvent(type, options)
17+
```
18+
19+
### 参数
20+
21+
- `type`
22+
- : 表示事件名称的字符串。区分大小写,浏览器会将其设置为 `command`
23+
- `options` {{optional_inline}}
24+
- : 一个对象,_除 {{domxref("Event/Event", "Event()")}} 中定义的属性外_,还可以包含下列属性:
25+
- `source` {{optional_inline}}
26+
- : 一个 {{domxref("HTMLButtonElement")}},表示触发该事件的按钮。虽然可以使用任意元素作为来源,但建议仅使用按钮以避免意外行为。
27+
- `command` {{optional_inline}}
28+
- : 一个字符串,表示受控元素应执行的命令。手动实例化 `CommandEvent` 时可以使用任意字符串,但建议使用内置名称或以两个连字符(`--`)为前缀,以确保向前兼容。
29+
30+
### 返回值
31+
32+
新的 {{domxref("CommandEvent")}} 对象。
33+
34+
## 规范
35+
36+
{{Specifications}}
37+
38+
## 浏览器兼容性
39+
40+
{{Compat}}
41+
42+
## 参见
43+
44+
- {{domxref("Invoker Commands API", "调用者命令 API", "", "nocode")}}
45+
- {{domxref("HTMLButtonElement.command")}}
46+
- {{domxref("HTMLButtonElement.commandForElement")}}
47+
- {{domxref("CommandEvent")}}

0 commit comments

Comments
 (0)