请问:javascript如何控制页面元素显示样式?
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN " "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd ">
<html xmlns= "http://www.w3.org/1999/xhtml ">
<head>
<meta http-equiv= "Content-Type " content= "text/html; charset=gb2312 " />
<title> 无标题文档 </title>
<SCRIPT language=JavaScript>
<!--
function fCheck(){
eval( "td1.background=\ "timages/2.jpg\ "; ");
//eval( "td1.style.background-color=\ "#00CC00\ "; ")
}
//-->
</SCRIPT>
</head>
<body>
<table width= "369 " height= "297 " border= "1 ">
<tr>
<td id= "td1 " onclick= "fCheck() " style= "background-color:#ffffff "> 点我一下 </td>
</tr>
</table>
</body>
</html>
这个javascript可以控制单元格显示背景,但是eval( "td1.style.background-color=\ "#00CC00\ "; ")这一句不能控制单元格背景改变颜色,怎样写能让单元格背景改变颜色?
------解决方案--------------------eval( "td1.style.background-color=\ "#00CC00\ "; ")
改为:
eval( "td1.style.backgroundColor=\ "#00CC00\ "; ")