aboutsummaryrefslogtreecommitdiff
path: root/files/zh-cn/web/api/customevent/initcustomevent/index.html
blob: ec20bb7e948c9fef17fa5fb678e421e3f5799954 (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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
---
title: CustomEvent.initCustomEvent()
slug: Web/API/CustomEvent/initCustomEvent
translation_of: Web/API/CustomEvent/initCustomEvent
---
<p>{{APIRef("DOM")}}{{deprecated_header}}</p>

<p><code><strong>CustomEvent.initCustomEvent()</strong></code> 方法初始化了一个 <code>CustomEvent</code> object. 如果该事件已经被分发出去,则不会在初始化过程中重复触发.</p>

<p>这类对象一定是由 {{ domxref("Document.createEvent()") }} 方法创建的. 该方法被分发之前必须通过{{ domxref("EventTarget.dispatchEvent()") }}方法设置.一旦被分发则,则无法被重新设置.</p>

<div class="note">
<p><strong>该方法已经作废,不要在新项目中继续使用该方法.</strong></p>

<p>Instead use specific event constructors, like {{domxref("CustomEvent.CustomEvent", "CustomEvent()")}}. The page on <a href="/en-US/docs/Web/Guide/Events/Creating_and_triggering_events">Creating and triggering events</a> gives more information about the way to use these.</p>
</div>

<h2 id="Syntax">Syntax</h2>

<pre class="syntaxbox"><em>event</em>.initCustomEvent(<em>type</em>, <em>canBubble</em>, <em>cancelable</em>, <em>detail</em>);
</pre>

<h3 id="Parameters">Parameters</h3>

<dl>
 <dt><code><em>type</em></code></dt>
 <dd>类型{{domxref("DOMString")}},事件名称.</dd>
 <dt><em><code>canBub</code></em><em><code>ble</code></em></dt>
 <dd>类型{{jsxref("Boolean")}},事件是否沿着dom树向上冒泡.</dd>
 <dt><code><em>cancelable</em></code></dt>
 <dd>类型{{jsxref("Boolean")}},事件是否可取消.</dd>
 <dt><em><code>deta</code></em><em><code>il</code></em></dt>
 <dd>事件初始化时传入的数据.</dd>
</dl>

<h2 id="Specifications">Specifications</h2>

<table class="standard-table">
 <thead>
  <tr>
   <th scope="col">Specification</th>
   <th scope="col">Status</th>
   <th scope="col">Comment</th>
  </tr>
 </thead>
 <tbody>
  <tr>
   <td>{{SpecName('DOM WHATWG','#dom-customevent-initcustomevent','CustomEvent')}}</td>
   <td>{{Spec2('DOM WHATWG')}}</td>
   <td>Initial definition, but already deprecated in favor of the use of a constructor, {{domxref("CustomEvent.CustomEvent", "CustomEvent()")}}</td>
  </tr>
 </tbody>
</table>

<h2 id="Browser_compatibility">Browser compatibility</h2>

{{Compat("api.CustomEvent.initCustomEvent")}}

<h2 id="See_also">See also</h2>

<ul>
 <li>{{domxref("CustomEvent")}}</li>
 <li>The constructor to use instead of this deprecated method: {{domxref("CustomEvent.CustomEvent", "CustomEvent()")}}.</li>
</ul>