点击时如何更改HTML表格单元格颜色

问题描述:

我试图在用户点击单元格时更改HTML表格单元格的背景颜色。任何想法如何做到这一点?我可以访问JS Prototype库,所以对Prototype或者直接Javascript的任何建议都会受到欢迎。

I'm trying to change the background color of an HTML table cell when the user clicks on the cell. Any ideas on how to do this? I have access to the JS Prototype library, so any suggestions for Prototype or straight Javascript would be welcome.

丑陋,但演示效果:

Ugly, but demonstrates the effect:

  <table>
    <tr>
        <td onclick="this.style.backgroundColor = 'Red';">Sample</td>
        <td onclick="this.style.backgroundColor = 'Blue';">Data</td>
    </tr>
  </table>