<!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>
<style>
#div1 {width:100px; height:100px; background:red; position:absolute;}
#div2 {width:100px; height:100px; background:yellow; position:absolute;}
</style>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>无标题文档</title>
<script>
window.onload=function()
{
var oTab=document.getElementById('tab1');
/*oTab.getElementsByTagName('tbody')[0].getElementsByTabName('tr')[2].getElementsByTagNmae('td')[1].innerHtml;*/
//Tbodies 获取所有的tbody
//rows 所有的行
//cells 获取所有的单元格 TD
//alert('oTab.tBodies[0].rows[2].cells[1].innHTML');
var oldBgColor='';
for(i=0;i<oTab.tBodies[0].rows.length;i++)
{
oTab.tBodies[0].rows[i].style.background=i%2?'#CCC':'';
//鼠标移入
oTab.tBodies[0].rows[i].onmouseover=function()
{
//把原先的背景色存起来
oldBgColor=this.style.background;
this.style.background='yellow';
};
//鼠标移出
oTab.tBodies[0].rows[i].onmouseout=function()
{
//防止隔行变色也被改变
this.style.background=oldBgColor;
}
}
}
</script>
</head>
<body>
<table id="tab1" border="1" width="400">
<thead>
<td>ID</td>
<td>姓名</td>
<td>操作</td>
</thead>
<tbody>
<tr>
<td>1</td>
<td>blue</td>
<td></td>
</tr>
<tr>
<td>2</td>
<td>Leo</td>
<td></td>
</tr>
<tr>
<td>3</td>
<td>默默</td>
<td></td>
</tr>
<tr>
<td>4</td>
<td>aaa</td>
<td></td>
</tr>
<tr>
<td>5</td>
<td>bbb</td>
<td></td>
</tr>
<tr>
<td>6</td>
<td>ccc</td>
<td></td>
</tr>
</tbody>
</table>
</body>
</html>