aboutsummaryrefslogtreecommitdiff
path: root/files/zh-cn/web/api/customevent/initcustomevent/index.html
blob: 2b8b12aea8359323f48ce8c0abaa5c94074dc63d (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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
---
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>

<p>{{ CompatibilityTable() }}</p>

<div id="compat-desktop">
<table class="compat-table">
 <tbody>
  <tr>
   <th>Feature</th>
   <th>Chrome</th>
   <th>Firefox (Gecko)</th>
   <th>Internet Explorer</th>
   <th>Opera</th>
   <th>Safari (WebKit)</th>
  </tr>
  <tr>
   <td>Basic support</td>
   <td>{{ CompatVersionUnknown() }}</td>
   <td>{{CompatGeckoDesktop(6)}}</td>
   <td>9</td>
   <td>11</td>
   <td>5.1 (533.3)</td>
  </tr>
 </tbody>
</table>
</div>

<div id="compat-mobile">
<table class="compat-table">
 <tbody>
  <tr>
   <th>Feature</th>
   <th>Android</th>
   <th>Firefox Mobile (Gecko)</th>
   <th>IE Phone</th>
   <th>Opera Mobile</th>
   <th>Safari Mobile</th>
  </tr>
  <tr>
   <td>Basic support</td>
   <td>{{ CompatUnknown() }}</td>
   <td>{{CompatGeckoMobile(6)}}</td>
   <td>{{ CompatUnknown() }}</td>
   <td>{{ CompatUnknown() }}</td>
   <td>{{ CompatUnknown() }}</td>
  </tr>
 </tbody>
</table>
</div>

<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>