求代码, HTML中如何用JS控制鼠标移入事件或点击事件来控制表格的背景颜色变换。

<table width="576" height="79" border="1">
<tr>
<td><div align="center" class="STYLE2">主页</div></td>
<td><div align="center" class="STYLE2">男装</div></td>
<td><div align="center" class="STYLE2">女装</div></td>
</tr>
</table>

<style type="text/css">
.STYLE1 {background-color:#f88}
.STYLE2 {background-color:#88f}
</style>
<table width="576" height="79" border="1">
<tr>
<td><div align="center" class="STYLE2" onmouseover="this.className='STYLE1'" onmouseout="this.className='STYLE2'">主页</div></td>
<td><div align="center" class="STYLE2" onmouseover="this.className='STYLE1'" onmouseout="this.className='STYLE2'">男装</div></td>
<td><div align="center" class="STYLE2" onmouseover="this.className='STYLE1'" onmouseout="this.className='STYLE2'">女装</div></td>
</tr>
</table>
温馨提示:内容为网友见解,仅供参考
第1个回答  2011-10-18
<!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=utf-8" />
<title>无标题文档</title>
<style type="text/css">
.style0{
background-color:#FFFF00;
}
.style1{
background-color:#00FFFF;
}
</style>
</head>

<body>
<table width="576" height="79" border="1">
<tr>
<td id="td1" onmousemove="document.getElementById('td1').className='style0';" onmouseout="document.getElementById('td1').className='style1'"><div align="center" class="STYLE2">主页</div></td>
<td><div align="center" class="STYLE2">男装</div></td>
<td><div align="center" class="STYLE2">女装</div></td>
</tr>
</table>
</body>
</html>
第2个回答  2011-10-18
其实css2用tr:hover{background-color:设置}就行,可惜有ie6
建议用jquery,用js写也可以,但是太麻烦
$("table tr").hover(function(){
this.bgColor = 设置;
});
写了个大概,具体自己写。
相似回答