var myObject = document.getElementById("header"); var myStyle = myObject.currentStyle.backgroundColor; 在Firefox中這樣寫:
var myObject = document.getElementById("header"); var myComputedStyle = document.defaultView.getComputedStyle(myObject, null); var myStyle = myComputedStyle.backgroundColor; 3. 訪問元素的”class” 像”float“一樣,”class“是JavaScript的一個(gè)保留字,在這兩個(gè)瀏覽器中我們使用如下句法來訪問”class”。 在IE中這樣寫:
var myObject = document.getElementById("header"); var myAttribute = myObject.getAttribute("className"); 在Firefox中這樣寫:
var myObject = document.getElementById("header"); var myAttribute = myObject.getAttribute("class"); This syntax would also apply using the setAttribute method.