關於最終樣式,IE和DOM在各自的實現上存在差異。
1.IE中的最終樣式,代碼如下:
<html><br /> <head><br /> <title>Accessing Style Sheets Example</title><br /> <style type="text/css"><br /> div.special {<br /> background-color: red;<br /> height: 10px;<br /> width: 10px;<br /> margin: 10px;<br /> }<br /> </style><br /> <script type="text/javascript"><br /> function getBackgroundColor() {<br /> var oDiv = document.getElementById("div1");<br /> alert(oDiv.currentStyle.backgroundColor);<br /> }<br /> </script></p><p> </head><br /> <body><br /> <div id="div1" class="special"></div><br /> <input type="button" value="Get Background Color" onclick="getBackgroundColor()" /><br /> <p>The alert displays nothing because the background color of the <code>div</code> is assigned by a class, not by the <code>style</code> attribute.</p><br /> </body><br /></html>
2.DOM中的最終樣式:
<html><br /> <head><br /> <title>Accessing Style Sheets Example</title><br /> <style type="text/css"><br /> div.special {<br /> background-color: red;<br /> height: 10px;<br /> width: 10px;<br /> margin: 10px;<br /> }<br /> </style><br /> <script type="text/javascript"><br /> function getBackgroundColor() {<br /> var oDiv = document.getElementById("div1");<br /> alert(document.defaultView.getComputedStyle(oDiv, null).backgroundColor);<br /> }<br /> </script></p><p> </head><br /> <body><br /> <div id="div1" class="special"></div><br /> <input type="button" value="Get Background Color" onclick="getBackgroundColor()" /><br /> <p>The alert displays nothing because the background color of the <code>div</code> is assigned by a class, not by the <code>style</code> attribute.</p><br /> </body><br /></html>