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(obj, false)[name]; <BR>} <BR>} <BR>window.onload=function() <BR>{ <BR>var oDiv=document.getElementById('div1'); <BR>alert(getStyle(oDiv, 'width')); <BR>alert(getStyle(oDiv, 'backgroundColor')); //注意在获取复合样式时要单独写,不能写background <BR>}; <BR>