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;
    }

js阻止事件冒泡和標籤默認行爲

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章