【JS兼容】一

http://sofish.de/1097
http://www.cnblogs.com/wiky/archive/2010/01/09/IE-and-Firefox-Javascript-compatibility.html

<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="utf-8" />
    <title></title>
    <link href="style.css" rel="stylesheet" />
</head>
<body>
    <div id="box1" class="box1">box1</div>
    <label id="box2" for="box2"></label>
    <script>
        var el1 = document.getElementById('box1'),
            el2 = document.getElementById('box2');
        // 保留字float
        el1.style.styleFloat = 'right';// IE
        el1.style.cssFloat = 'right';// 非IE
        // 保留字class
        el1.getAttribute('className');// IE6 IE7
        el1.getAttribute('class');// IE8 非IE
        // 保留字for
        el2.getAttribute('htmlFor');// IE6 IE7
        el2.getAttribute('for');// IE8 非IE
        // 获取可见区域、窗口的大小
        document.documentElement.clientWidth;// IE 非IE
        document.documentElement.clientHeight;// IE 非IE
        window.innerWidth;// 非IE
        window.innerHeight;// 非IE
        // Alpha透明
        el1.style.filter = 'alpha(opacity=80)';// IE
        el1.style.opacity = '0.8';// 非IE
        // 元素的推算样式
        /*
        *JavaScript可以使用object.style.property句法,方便地在外部访问和修改某个CSS样式,但其限制是这些句法只能取出已设的行内样式或者直接由JavaScript设定的样式。并不能访问某个外部的样式表
        */
        if (!-[1,]) {// 判断IE
            el1.currentStyle.color;// IE
        } else {
            document.defaultView.getComputedStyle(el1, null).color;// 非IE 
        }
        // 获取鼠标指针的位置
        document.onmousemove = function(e) {
            e = window.event || e;// window.event IE event 非IE
            el1.innerHTML = 'x:' + e.clientX + 'y:' + e.clientY;// IE 非IE
            el1.innerHTML = 'x:' + e.pageX + 'y:' + e.pageY;// 非IE
        };
    </script>
</body>
</html>
原文地址:https://www.cnblogs.com/jzm17173/p/2875225.html