JavaScript event.currentTarget与此 [英] JavaScript event.currentTarget vs this

查看:72
本文介绍了JavaScript event.currentTarget与此的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

event.currentTarget this 之间是否有区别?性能如何?

Is there a difference between event.currentTarget and this? What about performance?

推荐答案

currentTarget 事件属性返回其元素事件侦听器触发了事件。这仅在捕获和冒泡期间特别有用。

The currentTarget event attribute returns the element whose event listeners triggered the event. This is only particularly useful during capturing and bubbling.

您也可以使用 this 关键字,但是当您使用Microsoft事件注册模型时,关键字未引用HTML元素。

You can also use this keyword, but when you use the Microsoft event registration model the this keyword doesn’t refer to the HTML element.

有关更多信息,请参见以下链接: http://www.quirksmode.org/js/events_order.html

Please see following link for more information: http://www.quirksmode.org/js/events_order.html

* Microsoft模式的问题 * l

但是,当您使用Microsoft事件注册模型时,此关键字不会引用HTML元素。再加上Microsoft模型中缺少类似于currentTarget的属性,这意味着如果您这样做

But when you use the Microsoft event registration model the this keyword doesn’t refer to the HTML element. Combined with the lack of a currentTarget–like property in the Microsoft model, this means that if you do

element1.attachEvent('onclick',doSomething)
element2.attachEvent('onclick',doSomething)

知道当前哪个HTML元素处理事件。这是Microsoft事件注册模型中最严重的问题,对我来说,这是从来没有使用过的原因,即使在仅IE / Win的应用程序中也是如此。

you cannot know which HTML element currently handles the event. This is the most serious problem with the Microsoft event registration model and for me it’s reason enough never to use it, not even in IE/Win only applications.

注意:可能是,现在解决了

Note:: it may be,now resolved it

这篇关于JavaScript event.currentTarget与此的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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