自己收集的兼容案例-js

设置 div 元素的不透明级别:

opacity:0.5;                    /*在IE9及以上和其他浏览器可用*/
filter: alpha(opacity-50);      /*在IE8及以下可用*/

获取屏幕的兼容方式

document.documentElement.clientWidth      //在IE11版本及搜狗和360
document.body.clientWidth;                //这个不能兼容IE11

绑定事件对象兼容

document.onclick=function(eve){
    eve=eve|| window.event;        //兼容IE和W3C  在较高版本的IE下无需兼容
    alert(eve);        //参数的长度为1,
    //如果是事件处理绑定函数,说明了浏览器默认会传递一个参数    
}

猜你喜欢

转载自blog.csdn.net/magic_xiang/article/details/82768809