JS怎么改变每个TD的背景呢????
<table border= "0 " width= "200 " id= "table1 " height= "515 " background= "images/left/border_bg.png " >
<tr> <TD> </TD> </tr>
<tr> <TD> </TD> </tr>
<tr> <TD> </TD> </tr>
<tr> <TD> </TD> </tr>
<tr> <TD> </TD> </tr>
<tr> <TD> </TD> </tr>
<tr> <TD> </TD> </tr>
</table>
JS怎么改变每个TD的背景呢????
这个我要写在一个JS里面。。不能在每个TD里响应事件。。。
就是在BODY ONLOAD里引发一个事件。。。来改变每个 表格 的背景。。
(是每个表格TD不是 TABLE)
请高手指点
------解决方案--------------------随便写了一个,启发一下,哈
<table border= "1 " width= "400 " id= "table1 " height= "315 ">
<tr> <TD> 1 </TD> </tr>
<tr> <TD> 2 </TD> </tr>
<tr> <TD> 3 </TD> </tr>
</table>
</body>
<script language= "JavaScript ">
<!--
var arrColor = new Array( "red ", "blue ", "green ");
var oTable = document.getElementById( "table1 ");
for (var i=0; i <oTable.cells.length; i++)
{
alert(oTable.cells(i));
oTable.cells(i).style.backgroundColor = arrColor[i];
};
//-->
</script>