兼容性问题处理总结

1.在IE6/7/8下

Object.prototype.toString.apply(null) 返回"[object Object]" Object.prototype.toString.apply(undefined) 同样返回"[object Object]"

2.IE8以下 JSON是不存在的

解决方法

var str = '{"a":100}'

// 1. JSON.parse : 将JSON格式的字符串转成JSON格式的对象

/*var o = JSON.parse(str);
    o.a=200;//{"a":200}
    console.log(o.a);
    console.log(JSON);*/
    
//在IE8以下,JSON是不存在的
console.log(eval("("+str+")")) 

3.获取上一个哥哥元素节点,兼容所有浏览器

 function getBrother(curEle) {
 
        var pre = curEle.previousSibling;
        
        while(pre)
        
        {
            if(pre.nodeType===1){
                return pre;
            }
            
            pre = pre.previousSibling;
            
            // pre等于哥哥节点的哥哥节点;
        }
    }

4.bind传参的方式和call方法一样; IE8以下不兼容

5.低版本ie获取可视区域宽高

var winW=document.body.clientWidth

var winH=document.body.clientHeight

6.兼容浏览器获取可视区域的方法

document.documentElement.clientWidth||docuemnt.body.clientWidth

document.documentElement.clientHeight||docuemnt.body.clientHeight

未完待更新


作者:Rocky1
链接:https://juejin.im/post/5c6392afe51d452bb8567459
来源:掘金
著作权归作者所有。商业转载请联系作者获得授权,非商业转载请注明出处。

猜你喜欢

转载自www.cnblogs.com/wxsa/p/10370605.html