我可以用什么属性 event.target?

我需要定义启动事件的元素。

Using
event.target

获取相应的元素。

我可以在那里使用哪些物质?

href

标识符

nodeName

即使在页面上,我也找不到有关它的很多信息 jQuery, 所以在这里,我希望有人能够完成上述列表。

EDIT

:

它可以很有用:
http://de.selfhtml.org/javascript/objekte/node.htm

http://de.selfhtml.org/javascr ... aften
已邀请:

窦买办

赞同来自:

如果你检查了
event.target

通过 firebug 或开发人员工具 chrome, 它会看到元素 span /例如,以下属性/ 将有任何元素的属性。 这取决于目标元素是什么:


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: "[url=http://www.w3.org/1999/xhtml"]http://www.w3.org/1999/xhtml"[/url]
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: "<span>click</span>"
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

詹大官人

赞同来自:

event.target

返回元素 DOM, 所以你可以获得任何属性 property/, 拥有 所以要更具体地说回答你的问题 , 你总是可以得到
nodeName

, 你可以得到
href


id

, 只要该元素

它有

定义
href


id

; 否则会退回
undefined

.

但是,您可以使用的内部事件处理程序
this

, 它也安装在元素中 DOM; 更容易。


$/'foo'/.bind/'click', function // {
// inside here, `this` will refer to the foo that was clicked
}/;

小姐请别说爱

赞同来自:

window.onclick = e => {
console.dir/e.target/; // use this in chrome
console.log/e.target/; // use this in firefox - click on tag name to view
}


https://i.stack.imgur.com/V8p6O.png
利用过滤属性


e.target.tagName
e.target.className
e.target.style.height // its not the value applied from the css style sheet, to get that values use `getComputedStyle//`

董宝中

赞同来自:

event.target

返回函数瞄准的节点。 这意味着您可以使用类似于您将获得的任何其他节点进行您想要的所有内容
document.getElementById


我尝试过。 jQuery


var _target = e.target;
console.log/_target.attr/'href'//;


返回一个错误 :

.attr 不起作用


_target.attributes.href.value

它正在工作。

风见雨下

赞同来自:

event.target


返回函数瞄准的节点。 这意味着您可以尽一切与您从中获得的任何其他结
document.getElementById

二哥

赞同来自:

查看特定节点的所有属性的简单方法 DOM 在 Chrome /我在上 v.69/ - 它是右键单击该项目,请选择 inspect, 然后不是查看标签 "Style" 点击 "Properties".

在“属性”选项卡中,您将看到特定元素的所有属性。

要回复问题请先登录注册