2、阻止默认事件和冒泡事件
2018-01-08 本文已影响0人
皮卡乒乓
<a ><div onclick="historyImg(this, event)" class="txt_more">更多</div></a>
function historyImg(dom, e) {
stopBubble(e);
stopDefault(e);
}
//阻止事件冒泡函数
function stopBubble(e) {
if(e && e.stopPropagation)
e.stopPropagation()
else
window.event.cancelBubble = true
}
// 阻止默认浏览器动作(W3C)
function stopDefault(e) {
if(e && e.preventDefault) {
e.preventDefault();
} else {
// IE中阻止函数器默认动作的方式
window.event.returnValue = false;
}
return false;
}