此页面由社区从英文翻译而来。了解更多并加入 MDN Web Docs 社区。

View in English Always switch to English

CustomEvent:initCustomEvent() 方法

Deprecated

Avoid using this feature in new projects. This feature may be a candidate for removal from web standards or browsers.

备注: 此特性在 Web Worker 中可用。

CustomEvent.initCustomEvent() 方法用于初始化 CustomEvent 对象。如果该事件已经被分发出去,则此方法什么都不做。

这类对象一定是由 Document.createEvent() 方法创建的。事件派发之前必须调用 EventTarget.dispatchEvent() 方法。一旦已经派发,则无法被重新设置。

备注:该方法已被弃用,请勿再使用。

与其使用该特性,不如使用特定的事件构造函数,如 CustomEvent()创建和派发事件一节提供了更多有关使用这些事件的方法的信息。

语法

js
initCustomEvent(type, canBubble, cancelable, detail)

参数

type

包含事件名称的字符串。

canBubble

表示事件是否沿着 DOM 向上冒泡的布尔值。

cancelable

表示事件是否可取消的布尔值。

detail

处理器可通过 CustomEvent.detail 属性获取的任何数据。

返回值

无(undefined)。

规范

规范
DOM
# dom-customevent-initcustomevent

浏览器兼容性

参见