CustomEvent.initCustomEvent() method initializes a CustomEvent object. If the event has already been dispatched, this method does nothing.

Events initialized in this way must have been created with the Document.createEvent() method. This method must be called to set the event before it is dispatched, using EventTarget.dispatchEvent() . Once dispatched, it doesn't do anything anymore.

Do not use this method anymore, as it is deprecated.

注意: Rather than using the feature, instead use specific event constructors, like CustomEvent() . The page on 创建和触发事件 gives more information about the way to use those.

句法

event.initCustomEvent(type, canBubble, cancelable, detail);
					

参数

type
DOMString containing the name of the event.
canBubble
布尔 indicating whether the event bubbles up through the DOM or not.
cancelable
布尔 indicating whether the event is cancelable.
detail

The data passed when initializing the event.

规范

规范 状态 注释
DOM
The definition of 'CustomEvent' in that specification.
实时标准 Initial definition, but already deprecated in favor of the use of a constructor, CustomEvent()

浏览器兼容性

The compatibility table on this page is generated from structured data. If you'd like to contribute to the data, please check out https://github.com/mdn/browser-compat-data and send us a pull request. 更新 GitHub 上的兼容性数据
桌面 移动
Chrome Edge Firefox Internet Explorer Opera Safari Android webview Chrome for Android Firefox for Android Opera for Android Safari on iOS Samsung Internet
initCustomEvent 弃用 Chrome Yes
Yes
59
canBubble , cancelable ,和 detail are optional parameters defaulting to false , false ,和 null 分别。
Edge 14 Firefox 6 IE 9 Opera 11 Safari 5.1 WebView Android Yes
Yes
59
canBubble , cancelable ,和 detail are optional parameters defaulting to false , false ,和 null 分别。
Chrome Android Yes
Yes
59
canBubble , cancelable ,和 detail are optional parameters defaulting to false , false ,和 null 分别。
Firefox Android 6 Opera Android Yes Safari iOS Yes Samsung Internet Android Yes
Yes
7.0
canBubble , cancelable ,和 detail are optional parameters defaulting to false , false ,和 null 分别。

图例

完整支持

完整支持

弃用。不要用于新网站。

弃用。不要用于新网站。

见实现注意事项。

另请参阅

元数据

  • 最后修改: