Colors 更改单元格背景色
Colors 更改单元格背景色,colors,background,Colors,Background,now=新数组(“一月”、“二月”、“三月”、“四月”、“五月”、“六月”、“七月”、“八月”、“九月”、“十月”、“十一月”、“十二月”); 单元格=document.getElementById('months').getElementsByTagName('td'); 对于(c=0;c
now=新数组(“一月”、“二月”、“三月”、“四月”、“五月”、“六月”、“七月”、“八月”、“九月”、“十月”、“十一月”、“十二月”);
单元格=document.getElementById('months').getElementsByTagName('td');
对于(c=0;c
我想更改当前月份单元格的背景和字体颜色。我为下表尝试了上面的代码,但似乎无法使其工作
<table class="hovertable" id="hovertable" name="hovertable">
<tbody id="months">
<tr>
<td class="style2">
<a href="01.htm">Jan</a></td>
<td class="style2">
<a href="02.htm">Feb</a></td>
<td class="style2">
<a href="03.htm">Mar</a></td>
<td class="style2">
<a href="04.htm">Apr</a></td>
<td class="style2">
<a href="05.htm">May</a></td>
<td class="style2">
<a href="06.htm">Jun</a></td>
</tr>
<tr>
<td class="style2">
<a href="07.htm">Jul</a></td>
<td class="style2">
<a href="08.htm">Aug</a></td>
<td class="style2">
<a href="09.htm">Sep</a></td>
<td class="style2">
<a href="10.htm">Oct</a></td>
<td class="style2">
<a href="11.htm">Nov</a></td>
<td class="style2">
<a href="12.htm">Dec</a></td>
</tr>
</tbody>
</table>
有什么想法吗?谢谢。此javascript应该满足您的要求:
now = new Array("Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec");
var d = new Date();
cells = document.getElementById('months').getElementsByTagName('td');
for (c = 0; c < cells.length; c++) {
if (c == d.getMonth()) {
cells[c].style.backgroundColor = 'red' //today's scripture reading
cells[c].style.color = 'white'
}
}
now=新数组(“一月”、“二月”、“三月”、“四月”、“五月”、“六月”、“七月”、“八月”、“九月”、“十月”、“十一月”、“十二月”);
var d=新日期();
单元格=document.getElementById('months').getElementsByTagName('td');
对于(c=0;c
只是想澄清一下……您要做的是在表格首次加载时突出显示当前月份?正确-当前月份的单元格背景颜色应该会发生变化,以便与其他月份不同。谢谢!我知道我错过了什么。
now = new Array("Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec");
var d = new Date();
cells = document.getElementById('months').getElementsByTagName('td');
for (c = 0; c < cells.length; c++) {
if (c == d.getMonth()) {
cells[c].style.backgroundColor = 'red' //today's scripture reading
cells[c].style.color = 'white'
}
}