六、DOM事件
1) DOM事件流
- . capture phase (捕获事件)(ie低版本没有)(ˈkæptʃə(r))
从window一次向下捕获到触发事件的元素
![](https://img.haomeiwen.com/i3735344/9ddc6baccdf46c38.png)
- . target phase (事件触发过程)
![](https://img.haomeiwen.com/i3735344/d69f6462864e1188.png)
- . bubble phase (冒泡过程)(load事件没有)
![](https://img.haomeiwen.com/i3735344/f77c98e95bc0bb1b.png)
2) 事件注册
![事件注册](https://img.haomeiwen.com/i3735344/6a3944a1d55bc8af.png?
imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
注 :elem.onclick可以注册多个
![](https://img.haomeiwen.com/i3735344/57534de71cbd2f2e.png)
通常不建议:
elem.oncilck = null;
3) 事件触发
![](https://img.haomeiwen.com/i3735344/e9000f7c183906c2.png)
4) 事件对象
![](https://img.haomeiwen.com/i3735344/f8686efa7bb177a4.png)
- . 属性
- type(事件类型)
- target(a标签时,a链接元素)
- currentTarget (当前处理事件节点的元素)
- . 方法
- stopPropagation (阻止冒泡W3C-阻止传播到父节点)
- preventDefault (阻止默认行为-如:打开链接)
- stopImmediatePropagation (阻止冒泡W3C-阻止传播到父节点并阻止后面的行为)
5) 事件分类
![](https://img.haomeiwen.com/i3735344/deb7364fbe6a6724.png)
网友评论