我想:的Javascript,设置DIV颜色到另一个div的颜色
document.getElementById('colorsdiv').style.backgroundColor =
document.getElementById(thediv).style.backgroundColor;
我知道thediv是有效的,因为如果我这样做: document.getElementById(thediv).style.backgroundColor = 'red';
则会变成红色。
如果我这样做: alert(document.getElementById(thediv).style.backgroundColor);
它是null
。
我也知道它在我的样式表中被设置为一种颜色,因为它以这种方式显示。
我需要做些什么才能使其发挥作用?
如果我有一个样式表:#divname {background-color:black;}我将如何在JavaScript中引用它?如果我想要做一些像document.getElementById('colorsdiv')。style.backgroundColor = style('divname')。backgroundColor; – user999684 2012-01-04 01:20:18
我使用了这个建议,它效果很好......谢谢 – user999684 2012-01-04 01:48:28
请接受如果它为你工作的答案。 – 2012-01-04 01:59:39