js中对于浏览器的冒泡和阻止默认事件的兼容性写法
//阻止默认行为
<script type="text/javascript">
function stopDefault( e ) {
if ( e && e.preventDefault ) //传入操作对象e而不是window.event,同时支持w3c的preventDefalut()方法所以是其它浏览器
e.preventDefault();
else
window.event.returnValue = false; //ie
return false;
}
//同理 两个都差不多阻止冒泡
function stopBubble(e){
if(e && e.stopPropagation)
// 因此它支持W3C的stopPropation()方法
e.stopPropagation();
else
// 否则,我们得使用IE的方法来取消事件冒泡
window.event.cancelBubble=true;
}
</script>

浙公网安备 33010602011771号