实例代码“Ctrl+/”提示“F11/ESC”全屏 返回 格式化 恢复 运行
x
 
1
<!DOCTYPE html>
2
<html>
3
<head>
4
    <title>IE Computed Styles Example</title>
5
    <style type="text/css">
6
        #myDiv {
7
            background-color: blue;
8
            width: 100px;
9
            height: 200px;
10
        }
11
    </style>
12
    <script type="text/javascript">
13
        function showComputedStyles(){
14
            var myDiv = document.getElementById("myDiv");
15
            var computedStyle = myDiv.currentStyle;
16
            alert(computedStyle.backgroundColor);   //"red"
17
            alert(computedStyle.width);             //"100px"
18
            alert(computedStyle.height);            //"200px"
19
            alert(computedStyle.border);            //undefined
20
            alert(computedStyle.borderLeftWidth);   //"1px"
21
        }
22
    </script>
23
</head>
24
<body>
25
    <div id="myDiv" style="background-color: red; border: 1px solid black"></div>
26
    <input type="button" value="Show Computed Styles" onclick="showComputedStyles()" />
27
    <p>(This example works only in IE &lt; 9.)</p>
28
</body>
29
</html>
30