我需要一点帮助,这可能看起来很简单,但我的网页上有一个反色按钮,我需要遍历类名为text
的元素。循环遍历类和改变颜色
下面的代码:
//Javascript File
var text = document.getElementsByClassName('text');
var button = document.getElementById('invertcolors');
function onClick() {
for (var i = 0; i < text.length; i++) {
//Do something like this:
//text[i].style.color =
}
}
button.addEventListener('click', onClick, false);
<!--Stuff here...-->
<div id="content">
<font id="text1" class="text">I walked in the forest</font>
<br>
<font id="text2" class="text">Through the grey concrete path</font>
<br>
<font id="text3" class="text">Holding on the dog</font>
</div>
<!--Stuff here...-->
我需要遍历变量i的元素,它们的颜色设置为白色。我不知道怎么样,有人可以帮忙吗?谢谢!
http://stackoverflow.com/questions/4766201/javascript-invert-color-on-all-elements-of-a-page这可能有助于 –
不要使用''标签 – j08691
什么是错的'text [i] .style.color = ...'?它应该工作 – ValLeNain