Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

注册事件的兼容性处理 #22

Open
zlluGitHub opened this issue Apr 27, 2018 · 0 comments
Open

注册事件的兼容性处理 #22

zlluGitHub opened this issue Apr 27, 2018 · 0 comments

Comments

@zlluGitHub
Copy link
Owner

  • 注册事件的方式

  1. ele.on事件类型 = function(){}
  2. addEventListener(事件类型,事件处理函数,useCapture) 第三个参数默认是false,冒泡阶段执行
  3. attachEvent(事件类型,事件处理函数)
  • 兼容性问题

  1. 注册的事件的处理函数中的,this指向不一致:
    使用addEventListener的方式注册的点击事件的回调函数中的this 指向target,但是使用attachEvent的方式注册点击事件的回调函数中的this 指向window。

  2. 3种注册事件的方式中,回调函数内获取事件对象的方式也是不一致的要让他们统一,在第二种的
    事件注册方式(attachEvent)中,手动给handler传递window.event。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant