What properties can I use with event.target?

后端 未结 7 2048
醉酒成梦
醉酒成梦 2020-12-07 07:39

I need to identify elements from which events are fired.

Using event.target gets the respective element.

What properties can I use from there?<

7条回答
  •  陌清茗
    陌清茗 (楼主)
    2020-12-07 08:34

    If you were to inspect the event.target with firebug or chrome's developer tools you would see for a span element (e.g. the following properties) it will have whatever properties any element has. It depends what the target element is:

    event.target: HTMLSpanElement
    
    attributes: NamedNodeMap
    baseURI: "file:///C:/Test.html"
    childElementCount: 0
    childNodes: NodeList[1]
    children: HTMLCollection[0]
    classList: DOMTokenList
    className: ""
    clientHeight: 36
    clientLeft: 1
    clientTop: 1
    clientWidth: 1443
    contentEditable: "inherit"
    dataset: DOMStringMap
    dir: ""
    draggable: false
    firstChild: Text
    firstElementChild: null
    hidden: false
    id: ""
    innerHTML: "click"
    innerText: "click"
    isContentEditable: false
    lang: ""
    lastChild: Text
    lastElementChild: null
    localName: "span"
    namespaceURI: "http://www.w3.org/1999/xhtml"
    nextElementSibling: null
    nextSibling: null
    nodeName: "SPAN"
    nodeType: 1
    nodeValue: null
    offsetHeight: 38
    offsetLeft: 26
    offsetParent: HTMLBodyElement
    offsetTop: 62
    offsetWidth: 1445
    onabort: null
    onbeforecopy: null
    onbeforecut: null
    onbeforepaste: null
    onblur: null
    onchange: null
    onclick: null
    oncontextmenu: null
    oncopy: null
    oncut: null
    ondblclick: null
    ondrag: null
    ondragend: null
    ondragenter: null
    ondragleave: null
    ondragover: null
    ondragstart: null
    ondrop: null
    onerror: null
    onfocus: null
    oninput: null
    oninvalid: null
    onkeydown: null
    onkeypress: null
    onkeyup: null
    onload: null
    onmousedown: null
    onmousemove: null
    onmouseout: null
    onmouseover: null
    onmouseup: null
    onmousewheel: null
    onpaste: null
    onreset: null
    onscroll: null
    onsearch: null
    onselect: null
    onselectstart: null
    onsubmit: null
    onwebkitfullscreenchange: null
    outerHTML: "click"
    outerText: "click"
    ownerDocument: HTMLDocument
    parentElement: HTMLElement
    parentNode: HTMLElement
    prefix: null
    previousElementSibling: null
    previousSibling: null
    scrollHeight: 36
    scrollLeft: 0
    scrollTop: 0
    scrollWidth: 1443
    spellcheck: true
    style: CSSStyleDeclaration
    tabIndex: -1
    tagName: "SPAN"
    textContent: "click"
    title: ""
    webkitdropzone: ""
    __proto__: HTMLSpanElement
    

提交回复
热议问题