currentStyle 1.複合樣式:currentStyle取不到例:background、margin 2.取預設樣式3.只能讀取 複製程式碼 程式碼如下: 取得計算後的樣式 <BR>#div1{ height:100px; background:#069;} <BR> <BR>//相容<BR>function getStyle(obj, name) <BR>{ <BR>if (obj.currentStyle) <BR>{ <BR>return obj.currentStyle[name]; <BR>} <BR>else <BR>{ <BR>return getComputedStyle(objutedStyle(objutse)[name];alse)[name]; <BR>} <BR>window.onload=function() <BR>{ <BR>var oDiv=document.getElementById('div1'); <BR>alert(getStyle(oDiv, 'width')); <BR>alert(getStyle(oDiv, 'width')); <BR>alert(getStyle(oDiv, 'width')); <🎜)); >alert(getStyle(oDiv, 'backgroundColor')); //注意在取得複合樣式時要單獨寫,不能寫background <BR>}; <BR>