阻止冒泡:
DOM:? e.stopPropagation()
IE8:? e.cancelBubble=true
阻止默認(rèn)事件:
DOM:? e.preventDefault()
IE8: e.returnValue = false
function stopBubble(e) {
//如果提供了事件對(duì)象,則這是一個(gè)非IE瀏覽器
if ( e && e.stopPropagation )
? ? //因此它支持W3C的stopPropagation()方法
? ? e.stopPropagation();
else
? ? //否則,我們需要使用IE的方式來取消事件冒泡
? ? window.event.cancelBubble = true;
}
//阻止瀏覽器的默認(rèn)行為
function stopDefault( e ) {
? ? //阻止默認(rèn)瀏覽器動(dòng)作(W3C)
? ? if ( e && e.preventDefault )
? ? ? ? e.preventDefault();
? ? //IE中阻止函數(shù)器默認(rèn)動(dòng)作的方式
? ? else
? ? ? ? window.event.returnValue = false;
? ? return false;
}