fre*_*ent 74 jquery events properties
我需要识别触发事件的元素.
使用event.target
获取相应的元素.
我可以在那里使用什么属性?
即使在jQuery页面上,我也找不到很多关于它的信息,所以这里希望有人可以完成上面的列表.
编辑:
这些可能会有所帮助:selfHTML节点属性和selfHTML HTML属性
Ric*_*ard 121
如果您要使用firebug或chrome的开发人员工具检查event.target,您会看到一个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: "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: "<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
Run Code Online (Sandbox Code Playgroud)
Mat*_*att 39
event.target
返回DOM元素,因此您可以检索具有值的任何属性/属性; 因此,要回答你的问题更具体,你将永远无法找回nodeName
,你可以检索href
和id
,所提供的元素有一个href
和id
定义; 否则undefined
将被退回.
但是,在事件处理程序中,您可以使用this
,也设置为DOM元素; 更容易.
$('foo').bind('click', function () {
// inside here, `this` will refer to the foo that was clicked
});
Run Code Online (Sandbox Code Playgroud)
bhv*_*bhv 15
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
}
Run Code Online (Sandbox Code Playgroud)
利用过滤器的优点
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()`
Run Code Online (Sandbox Code Playgroud)
小智 6
event.target
返回该函数所针对的节点.这意味着您可以对任何其他节点执行任何操作,例如您可以使用的节点document.getElementById
我试过jQuery
var _target = e.target;
console.log(_target.attr('href'));
Run Code Online (Sandbox Code Playgroud)
返回错误:
.attr不起作用
但是_target.attributes.href.value
有效.
归档时间: |
|
查看次数: |
125928 次 |
最近记录: |