根据我的实验,这引用了event.currentTarget对象.
这种行为是否在标准的某处提到过?
根据“JavaScript The Definitive Guide”一书,这指的是似乎错误的事件目标. event.currentTarget似乎更合乎逻辑,因为事件处理程序被调用为HTML元素对象的方法.
有人可以澄清一下吗?
In case of bubbling I see “this” changes and means the
event.currentTarget.
解决方法
我在HTML5 event handler processing algorithm中找到了一个参考:
Invoke
callback
with one argument,the value of which is the Event objectE
,with the callback this value set toE
‘scurrentTarget
.
DOM 3级事件规范在以前的版本中没有说太多 – 它本来是语言无关的. Appendix F: ECMAScript Language Binding刚才说明了
EventListener function:
This function has no return value. The parameter shall be an object that implements theEvent
interface.
但是,当前版本省略了这些绑定.在其词汇表附录event listeners中描述:
event handler,event listener: An object that implements the
EventListener
interface and provides anEventListener.handleEvent()
callback method. Event handlers are language-specific. Event handlers are invoked in the context of a particular object (the 07003) and are provided with theevent
object itself.
此外,即将推出的DOM Level 4草案,其goals包含将DOM与EcmaScript的需求对齐,确实明确说明了in the Dispatching Events section:
If
listener
‘s callback is a Function object,its 07006 is theevent
‘s 07007 attribute value.
原文地址:https://www.jb51.cc/js/158452.html
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。