翻譯不完整。請協助 翻譯此英文文件。
EventTarget 是可以接收事件和監聽的物件實現的接口。
Element、document 和 window 為最常見的EventTarget ,但是也有其他的 Object 同樣也是 EventTarget ,例如 XMLHttpRequest、AudioNode、AudioContext……等等。
許多事件的目標,例如 elements、documents、windows,可以藉由 properties 和attributes 設置 event handlers 。
方法
EventTarget.addEventListener()- 註冊對
EventTarget的事件監聽 EventTarget.removeEventListener()- 移除對
EventTarget的事件監聽 EventTarget.dispatchEvent()- 對
EventTarget調度事件
Mozilla chrome code 的額外 Methods
Mozilla extensions for use by JS-implemented event targets to implement on* properties. See alsoWebIDL bindings.
- void setEventHandler(DOMString type, EventHandler handler)
- EventHandler getEventHandler(DOMString type)
技術文件
| Specification | Status | Comment |
|---|---|---|
| DOM The definition of 'EventTarget' in that specification. |
Living Standard | No change. |
| Document Object Model (DOM) Level 3 Events Specification The definition of 'EventTarget' in that specification. |
Working Draft | A few parameters are now optional (listener), or accepts the null value (useCapture). |
| Document Object Model (DOM) Level 2 Events Specification The definition of 'EventTarget' in that specification. |
Recommendation | Initial definition. |
瀏覽器相容性
| Feature | Chrome | Firefox (Gecko) | Internet Explorer | Opera | Safari (WebKit) |
|---|---|---|---|---|---|
| Basic support | 1.0 | 1.0 (1.7 or earlier) | 9.0 | 7 | 1.0 |
| Feature | Android | Firefox Mobile (Gecko) | IE Mobile | Opera Mobile | Safari Mobile |
|---|---|---|---|---|---|
| Basic support | 1.0 | 1.0 (1) | 9.0 | 6.0 | 1.0 |
參見
- Event reference - the events available in the platform.
- Event developer guide
Eventinterface

