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

WBOY
Release: 2016-06-24 11:19:40
Original
1043 people have browsed it

获取非行间样式:

<!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>
Copy after login

 

source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template