<table border=0 width=100>
<tr><td id=a1>aaaaaaaaaaa</td></tr>
<tr><td id=b1>bbbbbbbbbbb</td></tr>
</table>
<script>
function setcolor()
{
a1.style.background="#ff0000";
b1.style.background="#0000ff";
}
</script>
<input type=button value="set color" onclick="setcolor()">

解决方案 »

  1.   

    <style>
    td.tdClass{background-color:#00ffff;}
    </style><table border=1>
    <tr><td id="td1">abc</td><td>lmn</td></tr>
    <tr><td onclick="this.style.backgroundColor='#ff0000'">click here</td><td>xyz</td>
    </tr></table>
    <input type=button onclick="document.all('td1').style.backgroundColor='#ffff00'" value="User ID"><br>
    <input type=button onclick="document.all.tags('table')[0].rows[0].cells[1].style.backgroundColor='#0000ff'" value="User Index"><br>
    <input type=button onclick="document.all.tags('table')[0].rows[1].cells[1].className='tdClass'" value="User Class"><br>
      

  2.   

    <table border=1 width=100>
    <tr>
    <td onmouseover="this.bgColor='red'" onmouseout="this.bgColor='green'">1233<br>456</td>
    </tr>
    </table>
      

  3.   

    什么样的动态,是鼠标移上变色,移走复原;还是根据不同的内容变。如果是前者,最简单的代码如下<td onmouseover="this.bgColor='red'" onmouseout="this.bgColor=''">