铸石粉生产厂家:怎么使用JavaScript在自定义函数里改变任意<td>的背景色

来源:百度文库 编辑:神马品牌网 时间:2024/04/27 18:06:24

javaScript可以通过CSS样式间接改变<td>背景颜色:

1。<td>必须有id号 即<td id="td1">。( 方便javaScript调用 document.getElementById("td1"))

2。CSS样式中背景颜色background-color,颜色格式#rrggbb,rgb(rr,gg,bb)(javaScript背景颜色backgroundColor)

范例html文件代码:
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title> 改变表格颜色</title>
</head>
<body>
<table width="400" border="1" cellspacing="0" cellpadding="0">
<tr>
<td id="td1" bgcolor="#000000"> </td><!--设置黑色的(实际为红色)-->
<td bgcolor="#000000"> </td>
</tr>
</table>
</body>
<script language="javascript" type="text/javascript">
<!--
document.getElementById("td1").style.backgroundColor="#FF0000";
//引用了td1单元格,改变backgroundColor值
-->
</script>
</html>