1.键盘检测兼容写方法
var key = e.keyCode || e.which || e.charCode;
2.阻止冒泡事件冒泡的兼容
e.stopPropagation ? e.stopPropagation():e.cancelBubble = true;
3.鼠标箭头事件对象的兼容
 obj.onclick = function(evt){
           var e = evt || event;
                alert(e);
            }
4.阻止浏览器默认事件兼容
e.preventDefault?e.preventDefault():e.returnValue = false;
5.获取非行间样式的兼容写法
function getStyle(obj,sName){
if(obj.currentStyle){
return obj.currentStyle[sName];
}else{
return getComputedStyle(obj,false)[sName];
}
}
6.ajax核心对象的兼容写法
    let xhr;
    if (window.ActiveXObject) { //ie
        xhr = new ActiveXObject("Microsoft.XMLHttp");
    } else { //非ie
        xhr =  new XMLHttpRequest();
 }

扫码关注我们
微信号:SRE实战
拒绝背锅 运筹帷幄

SRE实战 互联网时代守护先锋,助力企业售后服务体系运筹帷幄!一键直达领取阿里云限量特价优惠。