<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>
<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>
解决方案 »
- 关于JS换行
- 如何用JS判断字母和汉字。。。?
- Mozilla Firefox 下的src问题请达人看一下
- 新手幼稚问题2:关于charset
- 求教 jsp、php 与javascript 之间相互传递参数问题?
- 鼠标焦点问题,请进来看看
- javascript里面可以得到IE的临时目录位置吗
- 模态对话框(window.showModalDialog),表单内容的提交、刷新父窗口的问题
- 请教网页上下载文件如何编写,急!
- 高分请教,如何再网页表单中进行日期......
- 在asp中用javascript的alert输出的是乱码,怎么解决?
- 请教javascript高手。能否帮我把这两段代码合在一起。
怎样枚举style的每个属性其实我想复制一个层及其所有子元素 例如 www.live.com 那样托动时的效果
var s="";
for(p in o.style){
s=s+p+":"+o.style[p]+"\n";
}
alert(s);
里面重要的一个属性就是cssText
o.style.cssText,以分号隔开
可以自己进行处理