js阻止事件冒泡和标签默认行为

////阻止事件冒泡函数 // 阻止默认浏览器动作(W3C) 要一起使用效果好
<a href="/Scripts/newfiber_js_lib/images/1.jpg" ><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) { // 阻止默认浏览器动作(W3C) if (e && e.preventDefault) { e.preventDefault(); } else { // IE中阻止函数器默认动作的方式 window.event.returnValue = false; } return false; }
原文地址:https://www.cnblogs.com/gaocong/p/5790438.html