一个兼容所有浏览器的阻止事件冒泡方法

function stopBubble(event) { //阻止冒泡事件
    //取消事件冒泡
    var e = arguments.callee.caller.arguments[0] || event; //若省略此句,下面的e改为event,IE运行可以,但是其他浏览器就不兼容
    if (e && e.stopPropagation) {
        // this code is for Mozilla and Opera
        e.stopPropagation();
    } else if (window.event) {
        // this code is for IE
        window.event.cancelBubble = true;
    }
}
posted @ 2019-07-23 15:01  纸飞机上的梦  阅读(640)  评论(0)    收藏  举报