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

查看:252
本文介绍了点击时如何更改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>

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

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