码迷,mamicode.com
首页 > 其他好文 > 详细

event.currentTarget与event.target

时间:2014-07-27 09:57:52      阅读:165      评论:0      收藏:0      [点我收藏+]

标签:

无意中在一段源码里看到event.currentTarget这个属性,这个与熟悉的event.target还是有所差别的。

event.target是指事件发生的源,在哪个元素上发生的。event.currentTarget 就是通过addEventListener绑定的DOM元素。事件是可以通过冒泡进行传递的。通过冒泡触发的事件event.target 跟event.currentTarget是不相同的元素。

引用网上的一段英文:Event objects also have target properties that reference the actual object which dispatched the event. In some cases, the target may not be the object for which you have registered a listener. This can occur when the object for which you have registered a listener contains a child component that also dispatches the same event (and the event bubbles). If you want to ensure that you are getting a reference to the object for which the listener is registered to listen for the event, use the currentTarget property。

event.currentTarget与event.target

标签:

原文地址:http://www.cnblogs.com/zsdblog/p/3870422.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!