JS浏览器兼容问题

解决浏览器兼容问题

获取事件对象兼容

oBtn.onclick=function(eve){
        var e = eve ||window.event
        }

获取事件目标兼容

oBtn.onclick=function(eve){
        var e = eve ||window.evente.target
        var target =e.target ||window.event
    }

阻止冒泡兼容

function stopBubble(e){
        if(e.stopPropgation){
            e.stopPropgation();
        }else{
            e.cancelBubble=true;
        }
    }

阻止系统自带功能

function preDef(e){
        if(e.preventDefault){
            e.preventDefault();
        }else{
            e.returnValue==false;
        }
    }

键码兼容

var which = e.keyCode || e.which;

字符码兼容

var which = e.charCode || e.which;
请用今天的努力,让明天没有遗憾。
原文地址:https://www.cnblogs.com/cupid10/p/15617765.html