Home > Web Front-end > HTML Tutorial > JS获取非行间样式及兼容问题 - Web学海无涯

JS获取非行间样式及兼容问题 - Web学海无涯

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
Release: 2016-05-20 16:50:26
Original
1099 people have browsed it

获取非行间样式:

"<span style="color: #800000;">en</span><span style="color: #800000;">"</span>>

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

    </script>


<div id="<span" style="color: #800000;">"<span style="color: #800000;">div1</span><span style="color: #800000;">"</span>></div>

Copy after login

 

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