JS event 兼容性写法

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/boonyaxnn/article/details/89197819
var stopObj = {
    'stopEvent': function () {
        //stopPropagation阻止事件传递至下一个节点
        if (event.stopPropagation) {
            //非IE浏览器
            event.stopPropagation();
        } else {
            //IE  cancelBubble阻止事件冒泡
            event.cancelBubble = true;
        }
    },
    'cancleDefault': function () {

        if (event.preventDefault) {
            //非IE浏览器  取消节点默认行为
            event.preventDefault();
        } else {
            //IE    取消节点默认行为
            event.returnValue = false;
        }
    }
};

猜你喜欢

转载自blog.csdn.net/boonyaxnn/article/details/89197819