Home >Web Front-end >HTML Tutorial >JS获取非行间样式及兼容问题_html/css_WEB-ITnose

JS获取非行间样式及兼容问题_html/css_WEB-ITnose

WBOY
WBOYOriginal
2016-06-24 11:19:401070browse

获取非行间样式:

<!DOCTYPE html><html lang="en"><head>    <meta charset="UTF-8">    <title>获取非行间样式</title>    <style>        #div1{height: 200px;width: 200px;background-color: red;}    </style>    <script>        function getStyle(obj,name){            if(obj.currentStyle){                return obj.currentStyle[name]; //IE浏览器            }            else if(getComputedStyle){      //Firefox,chrome浏览器                return getComputedStyle(obj,null)[name];            }        }        window.onload = function(){            var oDiv = document.getElementById('div1');            alert(getStyle(oDiv,'height'));        }    </script></head><body><div id="div1"></div></body></html>

 

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn