弃用
This feature is no longer recommended. Though some browsers might still support it, it may have already been removed from the relevant web standards, may be in the process of being dropped, or may only be kept for compatibility purposes. Avoid using it, and update existing code if possible; see the
兼容性表格
at the bottom of this page to guide your decision. Be aware that this feature may cease to work at any time.
Event.initEvent()
method is used to initialize the value of an
event
created using
Document.createEvent()
.
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.
Instead use specific event constructors, like
Event()
. The page on
创建和触发事件
gives more information about the way to use these.
event.initEvent(type, bubbles, cancelable);
type
DOMString
defining the type of event.
bubbles
布尔
deciding whether the event should bubble up through the event chain or not. Once set, the read-only property
Event.bubbles
will give its value.
cancelable
布尔
defining whether the event can be canceled. Once set, the read-only property
Event.cancelable
will give its value.
// Create the event. var event = document.createEvent('Event');// Create a click event that bubbles up and // cannot be canceledevent.initEvent('click', true, false); // Listen for the event. elem.addEventListener('click', function (e) { // e.target matches elem }, false); elem.dispatchEvent(event);
| 规范 | 状态 | 注释 |
|---|---|---|
|
DOM
The definition of 'Event.initEvent()' in that specification. |
实时标准 | 从 DOM (文档对象模型) 2 级事件规范 , deprecated it, superseded by event constructors. |
|
DOM (文档对象模型) 2 级事件规范
The definition of 'Event.initEvent()' in that specification. |
过时 | 初始定义。 |
| 桌面 | 移动 | |||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
initEvent
弃用
|
Chrome Yes | Edge 12 |
Firefox
17
|
IE Yes | Opera Yes | Safari Yes | WebView Android Yes | Chrome Android Yes |
Firefox Android
17
|
Opera Android Yes | Safari iOS Yes | Samsung Internet Android Yes |
完整支持
弃用。不要用于新网站。
见实现注意事项。
Event()
. More specific constructors can be used too.
事件
AbortController
AbortSignal
AbstractRange
Attr
ByteString
CDATASection
CSSPrimitiveValue
CSSValue
CSSValueList
CharacterData
ChildNode
注释
CustomEvent
DOMConfiguration
DOMError
DOMErrorHandler
DOMException
DOMImplementation
DOMImplementationList
DOMImplementationRegistry
DOMImplementationSource
DOMLocator
DOMObject
DOMParser
DOMPoint
DOMPointInit
DOMPointReadOnly
DOMRect
DOMString
DOMTimeStamp
DOMTokenList
DOMUserData
Document
DocumentFragment
DocumentType
元素
ElementTraversal
Entity
EntityReference
EventTarget
HTMLCollection
MutationObserver
节点
NodeFilter
NodeIterator
NodeList
NonDocumentTypeChildNode
ProcessingInstruction
PromiseResolver
范围
StaticRange
文本
TextDecoder
TextEncoder
TimeRanges
TreeWalker
TypeInfo
USVString
UserDataHandler
XMLDocument