我想:的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