1 回答
TA贡献2012条经验 获得超12个赞
<html>
<head>
<meta charset="utf-8">
<title>无标题文档</title>
<script>
window.onload=function(){
var qwe=document.getElementById('tab');
var tbRows = qwe.tBodies[0].rows;
for(var i=0; i<tbRows.length;i++)
{
if(i%2)
{
tbRows[i].style.background='#fff';
}
else{
tbRows[i].style.background='#ccc';
}
}
}
</script>
</head>
<body>
<table id="tab" width="500px">
<thead>
<tr><td>序号</td>
<td>名字</td>
<td>年龄</td>
</tr></thead>
<tbody>
<tr>
<td>1</td>
<td>张三</td>
<td>23</td>
</tr>
<tr>
<td>2</td>
<td>赵六</td>
<td>34</td>
</tr>
<tr>
<td>3</td>
<td>王五</td>
<td>12</td>
</tr>
<tr>
<td>4</td>
<td>李四</td>
<td>23</td>
</tr>
</tbody>
</table>
</body>
</html>
把qwe.tBodies[0].rows定义在for循环外
添加回答
举报