鼠标经过时单元格变色


<html >
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>鼠标经过时单元格变色</title>
<style type="text/css">
table{
 color:#565;
 font:12px Arial, Helvetica, sans-serif;
 }
td{
    border-bottom:2px solid #b3de94;
 border-top:3px solid #fff;
 padding:9px;
 }
tr:hover,td.hover{
 background-color:#595;
 color:#fff;
 }
tr{
 background-color:#dfc;
 }
</style>
</head>

<body>
<table summary="book list">
<caption>Book List</caption>
<tr>
<td>Title</td>
<td>Tom</td>
<td>Aom</td>
<td>Tina</td>
<td>Os</td>
</tr>
<tr>
<td>tom</td>
<td>1554658</td>
<td>china</td>
<td>$785</td>
<td>download</td>
</tr>
<tr>
<td>tom</td>
<td>1554658</td>
<td>china</td>
<td>$785</td>
<td>download</td>
</tr>
<tr>
<td>tom</td>
<td>1554658</td>
<td>china</td>
<td>$785</td>
<td>download</td>
</tr>
<tr>
<td>tom</td>
<td>1554658</td>
<td>china</td>
<td>$785</td>
<td>download</td>
</tr>
</table><br />
<script language="javascript">
var cells=document.getElementsByTagName('td');//rows是一个行的数组帮韩当前页中所有的行
for(var i=0;i<cells.length;i++)
{
 cells[i].onmouseover=function(){
  this.className='hover';
  //上变色
  for(var j=0;j<cells.length;j++)
  if(cells[j]==this){
   
  cells[j%5].className='hover';
  cells[j-j%5].className='hover';
  //左变色
  }
    
  }
 cells[i].onmouseout=function(){
  this.className='';
  for(var j=0;j<cells.length;j++)
  if(cells[j]==this){
   
  cells[j%5].className='';
  cells[j-j%5].className='';
  //左变色
  }
  //上恢复
  //左恢复
  }
 }
</script>
</body>
</html>

posted @ 2011-10-13 09:42  爱上冰糖雪梨的味道  阅读(1211)  评论(0编辑  收藏  举报