<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<style>
td{
width:100px;
height:40px;
}
</style>
</head>
<body>
<table border="1" style="border-collapse:collapse;">
<tbody id="tb">
<tr>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
</tr>
<tr>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
</tr>
<tr>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
</tr>
<tr>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
</tr>
<tr>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
</tr>
</tbody>
</table>
<script>
function my$(id){return document.getElementById(id)};
//获取父级元素
var tb = my$("tb");
//获取子元素的所有节点
var trs = tb.children;
console.log(trs);
//隔行变色
for(var i = 0; i < trs.length; i++){
if(i % 2 == 0){
trs[i].style.backgroundColor = "pink";
}else{
trs[i].style.backgroundColor = "skyblue";
}
}
</script>
</body>
</html>