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

[js] 70. IE 和 DOM 事件流的区别 #239

Open
qiilee opened this issue Sep 30, 2019 · 0 comments
Open

[js] 70. IE 和 DOM 事件流的区别 #239

qiilee opened this issue Sep 30, 2019 · 0 comments
Labels

Comments

@qiilee
Copy link
Member

qiilee commented Sep 30, 2019

答案:

1.事件流的区别

IE 采用冒泡型事件 Netscape 使用捕获型事件 DOM 使用先捕获后冒泡型事件
示例:

复制代码代码如下:

<body>
  <div>
    <button>点击这里</button>
  </div>
</body>

冒泡型事件模型: button->div->body (IE 事件流)

捕获型事件模型: body->div->button (Netscape 事件流)

DOM 事件模型: body->div->button->button->div->body (先捕获后冒泡)

2.事件侦听函数的区别

IE 使用:

[Object].attachEvent("name_of_event_handler", fnHandler); //绑定函数
[Object].detachEvent("name_of_event_handler", fnHandler); //移除绑定

DOM 使用:

[Object].addEventListener("name_of_event", fnHandler, bCapture); //绑定函数
[Object].removeEventListener("name_of_event", fnHandler, bCapture); //移除绑定

bCapture 参数用于设置事件绑定的阶段,true 为捕获阶段,false 为冒泡阶段。

@qiilee qiilee added the JS label Sep 30, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant