# JavaScript之捕捉模型与冒泡模型

> 在 模型中 支持第3个参数来声明事件的模型为冒泡还是捕捉，如果声明为 ，则为冒泡方式 捕捉模型与冒泡模型在IE下测试

- 原文：https://feinterview.poetries.top/blog/JavaScript%E4%B9%8B%E6%8D%95%E6%8D%89%E6%A8%A1%E5%9E%8B%E4%B8%8E%E5%86%92%E6%B3%A1%E6%A8%A1%E5%9E%8B
- 来源：前端进阶之旅（feinterview.poetries.top）
- 更新：2016-07-27

---

- 在`w3c`模型中 `addEventListener`支持第3个参数来声明事件的模型为冒泡还是捕捉，如果声明为`false`，则为冒泡方式
<!--more-->
```javascript
window.onload = function (){//ev激发的过程自动为函数传一个参数  鼠标的一系列动作包装成对象自动传给函数
	document.getElementById('par').addEventListener ('click',function (ev){alert(ev.pageX)},true);
	document.getElementById('son').addEventListener ('click',function (){alert('son')});
	

}
```

- 捕捉模型与冒泡模型在IE下测试

```javascript
window.onload = function (){//对于IE 当事件发生的瞬间 事件对象赋值给window.event属性
	document.getElementById('par').attachEvent ('onclick',function (ev){alert(window.event)});//IE下不支持第三个参数 true  
	document.getElementById('son').attachEvent ('onclick',function (){alert('son')});
	

}
```
