隔行变色2

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gbk">
<title>Insert title here</title>
<script>
 window.onload= function()
 {
 
var oTab=document.getElementById('tab1');
for (var i=0;i<oTab.tBodies[0].rows.length;i++)
{

if(i%2)
{
oTab.tBodies[0].rows[i].style.background="red";
}
else
{
oTab.tBodies[0].rows[i].style.background="#ccc";
}
}
 }

</script>
</head>
<body>
<table id='tab1' border="1" width="500">
<thead>
<td>ID</td>
<td>姓名</td>
<td>年龄</td>
</thead>
<tbody>
<tr>
<td>1</td>
<td>a</td>
<td>11</td>
</tr>
<tr>
<td>2</td>
<td>b</td>
<td>12</td>
</tr>
<tr>
<td>3</td>
<td>c</td>
<td>13</td>
</tr>
<tr>
<td>4</td>
<td>d</td>
<td>14</td>
</tr>
</tbody>
</table>


</body>
</html>

你可能感兴趣的:(隔行变色2)