首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > 编程 >

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

2013-03-10 
隔行换色,鼠标移动到的行换色!DOCTYPE html PUBLIC -//W3C//DTD XHTML 1.0 Transitional//EN http://w

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

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

热点排行