Home  >  Article  >  Web Front-end  >  addEventListener和attachEvent二者绑定的执行函数中的this不相同_基础知识

addEventListener和attachEvent二者绑定的执行函数中的this不相同_基础知识

WBOY
WBOYOriginal
2016-05-16 17:47:121002browse

写 addEventListener 和 attachEvent 区别的博文不少,不过大部分都把重点放置于前者是Firefox chrome,后者只是存在于IE系列中。

最近在写一个事件代理的时候,遇到一个BUG,发现除此外,二者绑定的执行函数中的 this 是不相同的,addEventListener 和 attachEvent函数在运行时候的上下文是不相同的。
用了一个简单的demo来描述这个不同点:

复制代码 代码如下:




测试




test2

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn