blob: 8b9c249c718c2685121b65c3ee1395cc9ee84be6 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
|
---
title: Event.createEvent()
slug: Web/API/Event/createEvent
tags:
- DOM
- Event
- JavaScript
- Method
translation_of: Web/API/Document/createEvent
translation_of_original: Web/API/Event/createEvent
---
<p>{{APIRef("DOM")}}</p>
<p>创建一个新的事件(Event),随之必须调用自身的 init 方法进行初始化。</p>
<h3 id="语法">语法</h3>
<pre><code>document.createEvent(type) </code></pre>
<dl>
<dt><code>type</code></dt>
<dd>指明待创建事件对象的类型的字符串</dd>
</dl>
<p>此方法返回一个新的特定类型的 DOM {{ domxref("Event") }} 对象,此对象在使用前必须经过初始化(init)。</p>
<h3 id="示例">示例</h3>
<pre>var newEvent = document.createEvent("UIEvents");</pre>
<h3 id="规范">规范</h3>
<ul>
<li><a class="external" href="http://www.w3.org/TR/DOM-Level-2-Events/events.html#Events-document" title="http://www.w3.org/TR/DOM-Level-2-Events/events.html#Events-document">DOM Level 2 Events</a></li>
</ul>
|