<!DOCTYPE html>
<html lang="zh-Hans">
<head>
<meta charset="UTF-8">
<title>Title</title>
</head>
<body>
<table>
<tr>
<td>24</td>
</tr>
<tr>
<td>24</td>
</tr>
<tr>
<td>24</td>
</tr>
<tr>
<td>24</td>
</tr>
<tr>
<td>24</td>
</tr>
<tr>
<td>24</td>
</tr>
<tr>
<td>24</td>
</tr>
<tr>
<td>24</td>
</tr>
</table>
<input type="button" value="测试隔行变色" onclick="getTr()" />
<script>
function getTr(){
var trlist=document.getElementsByTagName("tr");
for(var i=0;i<trlist.length;i++){
if(i%2==0){
trlist[i].style.backgroundColor="red";
}else{
trlist[i].style.backgroundColor="green";
}
}
}
</script>
</body>
</html>