javaScript+CSS實現表格變色

來源:互聯網
上載者:User

<!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>

相關文章

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.