什么属性可以用于event.target? [英] What properties can I use with event.target?
问题描述
我需要确定触发事件的元素。
I need to identify elements from which events are fired.
使用 event.target
获取相应的元素。
从哪里可以使用什么属性?
What properties can I use from there?
- href
- id
- nodeName
我找不到很多信息,即使在 jQuery 页面,所以这里是希望有人可以完成上面的列表。
I cannot find a whole lot of info on it, even on the jQuery pages, so here is to hoping someone can complete the above list.
编辑
这些可能有帮助: selfHTML节点属性和 selfHTML HTML属性
推荐答案
event.target
返回DOM元素,因此您可以检索具有值的任何属性/属性;所以要更具体地回答你的问题,你将始终能够检索 nodeName
,你可以检索 href
和 id
,只要元素具有一个 href
和 id
定义;否则未定义
将被返回。
event.target
returns the DOM element, so you can retrieve any property/ attribute that has a value; so, to answer your question more specifically, you will always be able to retrieve nodeName
, and you can retrieve href
and id
, provided the element has a href
and id
defined; otherwise undefined
will be returned.
但是,在事件处理程序中,您可以使用这个
也被设置为DOM元素;更容易。
However, inside an event handler, you can use this
, which is set to the DOM element as well; much easier.
$('foo').bind('click', function () {
// inside here, `this` will refer to the foo that was clicked
});
这篇关于什么属性可以用于event.target?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!