美文网首页
非行间的兼容问题

非行间的兼容问题

作者: 唐墨痕 | 来源:发表于2017-02-16 21:13 被阅读0次
    <!DOCTYPE html>
    <html lang="en">
    <head>
        <meta charset="UTF-8">
        <title>Title</title>
        <style>
            #odiv{
                background: red;
                height: 200px
            }
        </style>
    </head>
    <body>
        <div id="odiv" style="width: 200px;"></div>
    </body>
    <script>
        window.onload=function () {
            var oDiv=document.getElementById('odiv');
            oDiv.onclick=function () {
                //未定义属性是undefined
                //未定义函数会报错
                if (oDiv.currentStyle){//兼容低版本浏览器
                    alert(oDiv.currentStyle.height);
                }else{
                    alert(getComputedStyle(oDiv,false).height);
                    //高版本浏览器   false  兼容低版本火狐
                }
            }
        };
    </script>
    </html>
    

    相关文章

      网友评论

          本文标题:非行间的兼容问题

          本文链接:https://www.haomeiwen.com/subject/faknittx.html