本文介绍了在事件处理程序中使用它的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在DOM级别3事件规范中,我试图找到这个关键字在事件处理函数内的含义。

I was trying to find the meaning of this keyword inside event handler function in the DOM level 3 event spec.

根据我的实验这个是指 event.currentTarget 对象。

As per my experiment this refers to the event.currentTarget object.

这个行为是在标准中的某个地方提到的吗?

Is this behavior mentioned somewhere in the standard?

根据JavaScript The Definitive Guide这本书这个是指事件目标,这似乎是错误的。 event.currentTarget 似乎更符合逻辑,因为事件处理程序被调用为HTML元素对象的方法。

As per "JavaScript The Definitive Guide" book this refers to the event target which seems to wrong. event.currentTarget seems more logical as event handlers are invoked as the method of the HTML element object.

有人可以请澄清?


推荐答案

确实,在这种情况下,最终指南是错误的。

Indeed, the Definitive Guide is wrong in that case.

我在:

DOM 3级事件规范没有'在以前的版本中就会说得很多 - 这意味着是语言agno STIC。 刚刚说明

The DOM level 3 event specification didn't say much about it in previous versions - it was meant to be language agnostic. The Appendix F: ECMAScript Language Binding just stated

当前版本省略了这些绑定。并在其术语表附录中被描述:

However, current versions omitted these bindings. And in its Glossary appendix event listeners are described:

另外,即将到来的DOM Level 4草案,其包含将DOM与EcmaScript的需求对齐,明确指出中的listener-invokerel =nofollow>

Also, the upcoming DOM Level 4 draft, whose goals contain aligning the DOM with the needs of EcmaScript, does explicitly state in the Dispatching Events section:

这篇关于在事件处理程序中使用它的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-03 13:59