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;
posted @ 2020-06-22 20:46  Cupid05  阅读(16)  评论(0编辑  收藏  举报