读书人

隔行换色鼠标搬动到的行换色

发布时间: 2013-03-10 09:38:39 作者: rapoo

隔行换色,鼠标移动到的行换色

<!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">
table()
tr{}
</style>
</head>

<body onload="changeColor()">
<table>
<tr>
<td>wowowo</td>
<td>wowowo</td>
<td>wowowo</td>
</tr>
<tr>
<td>lalala</td>
<td>lalala</td>
<td>lalala</td>
</tr>
<tr>
<td>hehehe</td>
<td>hehehe</td>
<td>hehehe</td>
</tr>
<tr>
<td>xixixi</td>
<td>xixixi</td>
<td>xixixi</td>
</tr>
<tr>
<td>hahaha</td>
<td>hahaha</td>
<td>hahaha</td>
</tr>
</table>
</body>
<script type="text/javascript">
function changeColor()
{
var trs= document.getElementsByTagName('tr');
for (var i=0;i<trs.length;i++){
if(i%2==0)
{trs[i].style.backgroundColor ='silver';}
else{trs[i].style.backgroundColor='gray';}
//绑定onmouseover和onmouseout事件
var oldColor;
trs[i].onmouseover=function()
{oldColor=this.style.backgroundColor;
this.style.backgroundColor='pink';}
trs[i].onmouseout=function()
{this.style.backgroundColor=oldColor;}
}
}
</script>
</html>

读书人网 >编程

热点推荐