如何用javascript修改table单元格的背景色?马上给分!
如何用javascript修改table单元格的背景色?
<html>
<head>
<script language="JavaScript" fptype="dynamicanimation">
<!--
function changColor()
{
document.form1.td1.bgcolor="'#FF9900";
}
//-->
</script>
</head>
<form name="form1">
<table border="1" width="100%" name="table1">
<tr>
<td width="50%" name="td1" onclick="changColor()">click here!</td>
<td width="50%"> </td>
</tr>
</table>
</form>
</body>
</html>
问题点数:20、回复次数:3Top
1 楼jackkui(键 之 舞 者)回复于 2004-08-01 13:26:31 得分 20
<tr><td id="td1">Test</td></tr>
使用的javascript语句是这样的:
document.getElementById("td1").style.backgroundColor="red";//你要的颜色
这样就可以,当然也可以修改其他的属性。Top
2 楼kunchengking(Chinaren)回复于 2004-08-01 13:46:38 得分 0
<html>
<head>
<script language="JavaScript">
<!--
function changColor()
{
document.getElementById("td1").style.backgroundColor="#FF9900";
}
//-->
</script>
</head>
<form name="form1">
<table border="1" width="100%" name="table1">
<tr>
<td width="50%" id="td1" onclick="changColor()">click here!</td>
<td width="50%"> </td>
</tr>
</table>
</form>
</html>
ok!!
tank you......Top
3 楼dropship(光荣与梦想)回复于 2004-08-01 14:01:07 得分 0
不行的。
我刚刚替你测试了。
我有一个办法就是:
<%
String a = null;
if((request.getParamter("a")==null);
a = "#FFFFFF";
else
a = request.getParamter("a");
%>
<table border="1" width="100%" bgColor="<%=a%>">
<tr>
<td width="50%" name="td1" onclick='<javascript:location.href="AdvSearchArticle.jsp&a = #FF9900"'>click here!</td>
<td width="50%"> </td>
</tr>
</table>
注意td是没有name属性的。
Top




