<!DOCTYPE html PUBLIC "-//W3C//DTDXHTML 1.0 Transitional//EN""http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<htmlxmlns="http://www.w3.org/1999/xhtml">
<head>
<metahttp-equiv="Content-Type" content="text/html;charset=utf-8" />
<title>隔行变色</title>
<script language="javascript"type="text/javascript">
function getColor(){
varta=document.getElementsByName("tab1");
vartr1=document.getElementsByTagName("tr");
//alert(color);
//alert(tr1.length);
for(var i=0;i<tr1.length;i++){
if(i%2==0){
//偶数为红色
tr1[i].style.backgroundColor="red";
}else{
//奇数为绿色
tr1[i].style.backgroundColor="green";
}
}
}
</script>
</head>
<body>
<table width="300" border="1"cellpadding="0" id="tab1">
<tr class="A">
<td colspan="4"> </td>
</tr>
<tr class="B">
<td colspan="4"> </td>
</tr>
<tr class="C">
<td colspan="4"> </td>
</tr>
<tr class="D">
<td colspan="4"> </td>
</tr>
</table>
<input type="button"value="点就变色"οnclick="getColor()">
</body>
</html>