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

Roh*_*han 5 html javascript css html-table cell

我正在尝试在用户单击单元格时更改HTML表格单元格的背景颜色.关于如何做到这一点的任何想法?我可以访问JS Prototype库,因此欢迎任何有关Prototype或直接Javascript的建议.

Lar*_*nal 3

丑陋,但演示了效果:

  <table>
    <tr>
        <td onclick="this.style.backgroundColor = 'Red';">Sample</td>
        <td onclick="this.style.backgroundColor = 'Blue';">Data</td>
    </tr>
  </table>
Run Code Online (Sandbox Code Playgroud)