From 33058f2b292b3a581333bdfb21b8f671898c5060 Mon Sep 17 00:00:00 2001 From: Peter Bengtsson Date: Tue, 8 Dec 2020 14:40:17 -0500 Subject: initial commit --- .../zh-cn/web/api/document/createevent/index.html | 189 +++++++++++++++++++++ 1 file changed, 189 insertions(+) create mode 100644 files/zh-cn/web/api/document/createevent/index.html (limited to 'files/zh-cn/web/api/document/createevent') diff --git a/files/zh-cn/web/api/document/createevent/index.html b/files/zh-cn/web/api/document/createevent/index.html new file mode 100644 index 0000000000..4148af1f48 --- /dev/null +++ b/files/zh-cn/web/api/document/createevent/index.html @@ -0,0 +1,189 @@ +--- +title: Document.createEvent() +slug: Web/API/Document/createEvent +translation_of: Web/API/Document/createEvent +--- +
+

createEvent使用的许多方法, 如 initCustomEvent, 都被废弃了. 请使用 event constructors 来替代.

+
+ +
{{ ApiRef("DOM") }}
+ +
 
+ +

创建一个指定类型的事件。其返回的对象必须先初始化并可以被传递给 element.dispatchEvent

+ +

语法

+ +
var event = document.createEvent(type);
+
+ + + +

示例

+ +
// 创建事件
+var event = document.createEvent('Event');
+
+// 定义事件名为'build'.
+event.initEvent('build', true, true);
+
+// 监听事件
+elem.addEventListener('build', function (e) {
+  // e.target matches elem
+}, false);
+
+// 触发对象可以是任何元素或其他事件目标
+elem.dispatchEvent(event);
+
+ +

参考

+ + + +

注意

+ +

Event type字符串只能传递事件模块中定义的值给CreateEvent。其中一些事件模块是在DOM事件规范定义的,还有些事在其他规范定义的(如SVG),还有一些是Gecko-specific事件。详情见下表。

+ +

To-do: 添加事件名称到下表中。

+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
事件模块传递给 createEvent的Event type事件初始化方法
DOM Level 2 Events
User Interface event module"UIEvents"event.initUIEvent
Mouse event module"MouseEvents"event.initMouseEvent
Mutation event module"MutationEvents"event.initMutationEvent
HTML event module"HTMLEvents"event.initEvent
DOM Level 3 Events
User Interface event module"UIEvent", "UIEvents"event.initUIEvent
Mouse event module"MouseEvent", "MouseEvents"event.initMouseEvent
Mutation event module"MutationEvent", "MutationEvents"event.initMutationEvent
Mutation name event module (not implemented in Gecko as of June 2006)"MutationNameEvent"event.initMutationNameEvent
Text event module"TextEvent" (Gecko also supports "TextEvents")event.initTextEvent (not implemented)
Keyboard event module"KeyboardEvent" (Gecko also supports "KeyEvents")event.initKeyEvent (Gecko-specific; the DOM 3 Events working draft uses initKeyboardEvent instead)
Custom event module {{gecko_minversion_inline("6.0")}}"CustomEvent"event.initCustomEvent
Basic events module"Event" (Gecko also supports "Events")event.initEvent
SVG 1.1 Scripting
SVG"SVGEvents" (Gecko also supports "SVGEvent")event.initEvent
"SVGZoomEvents" (Gecko also supports "SVGZoomEvent")event.initUIEvent
Other event types supported by Gecko
-"MessageEvent" {{Fx_minversion_inline(3)}} {{Gecko_minversion_inline(1.9)}}event.initMessageEvent
"MouseScrollEvents", "PopupEvents"event.initMouseEvent
"PopupBlockedEvents"event.initPopupBlockedEvent
"XULCommandEvent", "XULCommandEvents"event.initCommandEvent
Progress Events"ProgressEvent"{{domxref("ProgressEvent.initProgressEvent()")}}{{deprecated_inline("22.0")}}{{non-standard_inline()}}
Animation Events"AnimationEvent" (or "WebKitAnimationEvent" for WebKit/Blink-based browsers){{domxref("AnimationEvent.initAnimationEvent()")}}{{deprecated_inline("23.0")}}{{non-standard_inline()}}
Transition Events"TransitionEvent" (or "WebKitTransitionEvent" for WebKit/Blink-based browsers){{domxref("TransitionEvent.initTransitionEvent()")}}{{deprecated_inline("23.0")}}{{non-standard_inline()}}
+ +

有些事件可以使用两种事件类型参数,这是因为DOM Level 3 Events将事件类型参数更改为单数形式,但是仍然支持老的复数形式以向后兼容。

+ +

规范

+ + + +

 

+ +

 

-- cgit v1.2.3-54-g00ecf