什么属性可以用于event.target? [英] What properties can I use with event.target?

查看:140
本文介绍了什么属性可以用于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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆