菜鸟问题!!!关于控制表格的单元格!

ldh_0421 2002-12-28 09:41:32
我想动态设置标个单元格的背景色,该怎么办?最好能提供源代码!
...全文
24 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
lbd8848 2002-12-28
  • 打赏
  • 举报
回复
<table border=0 width=100>
<tr><td id=a1>aaaaaaaaaaa</td></tr>
<tr><td id=b1>bbbbbbbbbbb</td></tr>
</table>
<script>
function setcolor()
{
a1.style.background="#ff0000";
b1.style.background="#0000ff";
}
</script>
<input type=button value="set color" onclick="setcolor()">
zhougong22 2002-12-28
  • 打赏
  • 举报
回复
什么样的动态,是鼠标移上变色,移走复原;还是根据不同的内容变。如果是前者,最简单的代码如下<td onmouseover="this.bgColor='red'" onmouseout="this.bgColor=''">
江南昆虫 2002-12-28
  • 打赏
  • 举报
回复
<table border=1 width=100>
<tr>
<td onmouseover="this.bgColor='red'" onmouseout="this.bgColor='green'">1233<br>456</td>
</tr>
</table>
liuzxit 2002-12-28
  • 打赏
  • 举报
回复
<style>
td.tdClass{background-color:#00ffff;}
</style>

<table border=1>
<tr><td id="td1">abc</td><td>lmn</td></tr>
<tr><td onclick="this.style.backgroundColor='#ff0000'">click here</td><td>xyz</td>
</tr></table>
<input type=button onclick="document.all('td1').style.backgroundColor='#ffff00'" value="User ID"><br>
<input type=button onclick="document.all.tags('table')[0].rows[0].cells[1].style.backgroundColor='#0000ff'" value="User Index"><br>
<input type=button onclick="document.all.tags('table')[0].rows[1].cells[1].className='tdClass'" value="User Class"><br>

87,996

社区成员

发帖
与我相关
我的任务
社区描述
Web 开发 JavaScript
社区管理员
  • JavaScript
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧