target
特性为
事件
interface is a reference to the object onto which the event was dispatched. It is different from
Event.currentTarget
when the event handler is called during the bubbling or capturing phase of the event.
const theTarget = someEvent.target;
event.target
property can be used in order to implement
event delegation
.
// Make a list
const ul = document.createElement('ul');
document.body.appendChild(ul);
const li1 = document.createElement('li');
const li2 = document.createElement('li');
ul.appendChild(li1);
ul.appendChild(li2);
function hide(evt) {
// e.target refers to the clicked <li> element
// This is different than e.currentTarget, which would refer to the parent <ul> in this context
evt.target.style.visibility = 'hidden';
}
// Attach the listener to the list
// It will fire when each <li> is clicked
ul.addEventListener('click', hide, false);
| 桌面 | 移动 | |||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
target
|
Chrome 1 | Edge 12 | Firefox 1 | IE 9 | Opera 7 | Safari 1 | WebView Android 1 | Chrome Android 18 | Firefox Android 4 | Opera Android 10.1 | Safari iOS 1 | Samsung Internet Android 1.0 |
完整支持
On IE 6–8, the event model is different. Event listeners are attached with the non-standard
EventTarget.attachEvent()
方法。
In this model, the event object has a
Event.srcElement
property (instead of the
target
property) and it has the same semantics as
Event.target
.
function hide(evt) {
// Support IE6-8
var target = evt.target || evt.srcElement;
target.style.visibility = 'hidden';
}
事件
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