EventTarget
Baseline Widely available *
This feature is well established and works across many devices and browser versions. It’s been available across browsers since July 2015.
* Some parts of this feature may have varying levels of support.
EventTarget
接口由可以接收事件、并且可以创建侦听器的对象实现。换句话说,任何事件目标都会实现与该接口有关的这三个方法。
Element
及其子项、document
和 window
是最常见的事件目标,但其他对象也可以是事件目标。比如 XMLHttpRequest
、AudioNode
和 AudioContext
等等。
许多事件目标(包括 element
、document
和 window
)都支持通过 onevent
特性和属性设置事件处理程序。
构造函数
EventTarget()
-
创建一个新的
EventTarget
对象实例。
方法
EventTarget.addEventListener()
-
在
EventTarget
上注册特定事件类型的事件处理程序。 EventTarget.removeEventListener()
-
EventTarget
中删除事件侦听器。 EventTarget.dispatchEvent()
-
将事件分派到此
EventTarget
。
规范
Specification |
---|
DOM # interface-eventtarget |
浏览器兼容性
Report problems with this compatibility data on GitHubdesktop | mobile | server | ||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
EventTarget | ||||||||||||||
EventTarget() constructor | ||||||||||||||
addEventListener | ||||||||||||||
Form with options object supported (third parameter can be either options or a Boolean , for backwards compatibility) | ||||||||||||||
options.capture parameter | ||||||||||||||
options.once parameter | ||||||||||||||
options.passive parameter | ||||||||||||||
options.passive parameter defaults to true for touchstart and touchmove events | ||||||||||||||
options.passive parameter defaults to true for wheel and mousewheel events | ||||||||||||||
options.signal parameter | ||||||||||||||
useCapture parameter is optional | ||||||||||||||
dispatchEvent | ||||||||||||||
removeEventListener | ||||||||||||||
Form with options object supported (third parameter can be either options or a Boolean , for backwards compatibility) | ||||||||||||||
useCapture parameter is optional |
Legend
Tip: you can click/tap on a cell for more information.
- Full support
- Full support
- Partial support
- Partial support
- No support
- No support
- See implementation notes.
- Has more compatibility info.
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.