<script language=javascript>
<!--
function changebgColor()
{
var obj=window.event.srcElement;
if(obj.style.backgroundColor=="blue")
{
obj.style.backgroundColor="red";
}
else
{
obj.style.backgroundColor="blue";
}

}
//-->
</script>
<TABLE id="Table1" cellSpacing="1" cellPadding="1" width="300" border="1">
<TR>
<TD onclick="changebgColor()" runat=server>afadsfasdfasdfa</TD><TD onclick="changebgColor()">afadsfasdfasdfa</TD><TD onclick="changebgColor()">afadsfasdfasdfa</TD>
</TR>
</TABLE>

解决方案 »

  1.   

    非常感谢 comy(泥娃) 我试过了,可以实现单击变色的功能,(看了光学asp.net还不行呀,还得学javascript是吧) 不过这只是第一步,我把每个单元个的TD都设置了id,请问我怎么才能知道 现在 用户点的是那个单元格,这可以实现吗?
      

  2.   

    你不需要知道 id ,让它自己认识自己吧!
         <table>
             <tbody>
             <tr>
               <td  onclick="this.bgColor='red'" onmouseout="this.bgColor='white'">hello</td>
             </tr>
             </tbody>
         </table>
      

  3.   

    标准答案<table>
    <td onclick="if (this.bgColor=='#ff0000'){this.bgColor='#0000ff'}else{this.bgColor='#ff0000'}">
    ....
    </td>
    ....
    </table>