event.stoppropagation的兼容

jquery的event.stoppropagation()是兼容firefox、chrome的,但不兼容ie

兼容写法:

        if (event.stopPropagation) {
            event.stopPropagation();
        }
        else if (window.event) {
            window.event.cancelBubble = true;
        }    

window.event在ie和chrome上是有的,firefox上没有window.event,需要函数中参数带入

    $(".dom").click(function (event) {
        if (event.stopPropagation) {
            event.stopPropagation();
        }
        else if (window.event) {
            window.event.cancelBubble = true;
        }
        ...
    });    

 

posted @ 2016-05-18 13:19  hpyou  阅读(670)  评论(0编辑  收藏  举报