--- title: CustomEvent.initCustomEvent() slug: Web/API/CustomEvent/initCustomEvent translation_of: Web/API/CustomEvent/initCustomEvent ---
{{APIRef("DOM")}}{{deprecated_header}}
CustomEvent.initCustomEvent()
方法初始化了一个 CustomEvent
object. 如果该事件已经被分发出去,则不会在初始化过程中重复触发.
这类对象一定是由 {{ domxref("Document.createEvent()") }} 方法创建的. 该方法被分发之前必须通过{{ domxref("EventTarget.dispatchEvent()") }}方法设置.一旦被分发则,则无法被重新设置.
该方法已经作废,不要在新项目中继续使用该方法.
Instead use specific event constructors, like {{domxref("CustomEvent.CustomEvent", "CustomEvent()")}}. The page on Creating and triggering events gives more information about the way to use these.
event.initCustomEvent(type, canBubble, cancelable, detail);
type
canBub
ble
cancelable
deta
il
Specification | Status | Comment |
---|---|---|
{{SpecName('DOM WHATWG','#dom-customevent-initcustomevent','CustomEvent')}} | {{Spec2('DOM WHATWG')}} | Initial definition, but already deprecated in favor of the use of a constructor, {{domxref("CustomEvent.CustomEvent", "CustomEvent()")}} |
{{ CompatibilityTable() }}
Feature | Chrome | Firefox (Gecko) | Internet Explorer | Opera | Safari (WebKit) |
---|---|---|---|---|---|
Basic support | {{ CompatVersionUnknown() }} | {{CompatGeckoDesktop(6)}} | 9 | 11 | 5.1 (533.3) |
Feature | Android | Firefox Mobile (Gecko) | IE Phone | Opera Mobile | Safari Mobile |
---|---|---|---|---|---|
Basic support | {{ CompatUnknown() }} | {{CompatGeckoMobile(6)}} | {{ CompatUnknown() }} | {{ CompatUnknown() }} | {{ CompatUnknown() }} |