JavaScript 阻止冒泡及默认行为
阻止冒泡
- e.cancalBubble = true:IE8- chrome
- e.stopPropagation():firefox chrome
兼容:
js
e.stopPropagation ? e.stopPropagation() : e.cancalBubble = true;
阻止默认行为
- 普通函数: return false
- addEventListener:e.preventDefault() // chrome
- attachEvent:e.returnValue = false // IE
兼容:
js
e.preventDefault ? e.preventDefault() : e.returnValue = false;
阻止IE选择事件
- onmousedown:setCapture() 设置捕获
- onkeydown:releaseCapture() 释放捕获