如何以编程方式将所有样式属性从一个DOM元素复制到另一个 [英] How can I programmatically copy all of the style attributes from one DOM element to another

查看:209
本文介绍了如何以编程方式将所有样式属性从一个DOM元素复制到另一个的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个页面有两个框架,我需要(通过javascript)复制一个元素和所有的嵌套元素(它是一个ul / li树),最重要的是它的样式从一个框架到另一个。 p>

我通过分配innerhtml获得所有内容,我可以使用dest.style.left和dest.style.top在第二个框架中定位新元素。
但我试图获得所有的样式信息,没有发生任何事情。



我使用getComputedStyle获取每个源元素的最终样式



我缺少什么?

$您是否尝试过 cloneNode 它可以复制元素及其所有的孩子一次。
http://www.w3schools.com/dom/met_element_clonenode.asp


I have a page with two frames, and I need to (via javascript) copy an element and all of its nested elements (it's a ul/li tree) and most importantly it's style from one frame to the other.

I get all the content via assigning innerhtml, and I am able to position the new element in the second frame with dest.style.left and dest.style.top and it works. But I'm trying to get all the style information and nothing's happening.

I'm using getComputedStyle to get the final style for each source element as I loop through each node then and assigning them to the same position in the destination nodelist and nothing happens to visually change the style.

What am I missing?

解决方案

Have you tried cloneNode? It can copy the element and all of its children in one fell swoop. http://www.w3schools.com/dom/met_element_clonenode.asp

这篇关于如何以编程方式将所有样式属性从一个DOM元素复制到另一个的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆