<div id="divMain" title="aa" style="color:red;">
<div id="s">aaaaaaq</div></div>
<script>/*function copyElement(o)
{
var newObject = document.createElement("div");
newObject.innerHTML=o.innerHTML; for( i=0;i<o.attributes.length;i++)
{
//alert();
newObject.setAttribute([o.attributes[i].nodeName],o.attributes[i].nodeValue);
document.write(o.attributes[i].nodeName+":"+o.attributes[i].nodeValue+"<br>");
}
document.body.appendChild(newObject);

}
copyElement(document.getElementById("divMain"));
*/
document.write(document.getElementById("divMain").attributes["style"].nodeValue);//为什么输出 null ?
</script>

解决方案 »

  1.   

    try this:document.getElementById("divMain").style
      

  2.   

    document.getElementById("divMain").style
    怎样枚举style的每个属性其实我想复制一个层及其所有子元素 例如 www.live.com 那样托动时的效果
      

  3.   

    var o=document.getElementById("divMain");
    var s="";
    for(p in o.style){
     s=s+p+":"+o.style[p]+"\n";
    }
    alert(s);
    里面重要的一个属性就是cssText
    o.style.cssText,以分号隔开
    可以自己进行处理