1 概述
阻止冒泡和默认事件都是js中非常重要的,其实很简单,只需要一到两句语法即可,关键在于需要做兼容!
2 阻止冒泡事件
function stopBubble(e) {
if(e && e.stopPropagation){
e.stopPropagation();
} else {
window.event.cancelBubble = true;
}
};
3 阻止默认事件
function stopDefault(e){
if(e && e.preventDefault) {
e.preventDefault();
} else {
window.event.returnValue = false;
}
return false;
};