如何在单击时更改 HTML 表格单元格颜色 [英] How do I change HTML table cell color on click

查看:39
本文介绍了如何在单击时更改 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.

推荐答案

丑,但是演示效果:

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

这篇关于如何在单击时更改 HTML 表格单元格颜色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆