javaScript+CSS实现表格变色

<!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 changeColor(row){
document.getElementById(row).style.backgroundColor='#CCCCFF';
}
function resetColor(row){
document.getElementById(row).style.backgroundColor='';
}
</script>
</head>

<body>
<table width="200" border="1" cellpadding="1" cellspacing="1">
<tr>
<th>学校</th>
<th>专业</th>
<th>人数</th>
</tr>
<tr align="center" id="row1" onmouseover="changeColor('row1')" onmouseout="resetColor('row1')">
<td>北大</td>
<td>法律</td>
<td>200</td>
</tr>
<tr align="center" id="row2" onmouseover="changeColor('row2')" onmouseout="resetColor('row2')">
<td>湖南农大</td>
<td>计算机</td>
<td>500</td>
</tr>
<tr align="center" id="row3" onmouseover="changeColor('row3')" onmouseout="resetColor('row3')">
<td>人大</td>
<td>经济</td>
<td>600</td>
</tr>
</table>
</body>
</html>

你可能感兴趣的:(javaScript+CSS实现表格变色)