<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>无标题文档</title>
</head>
<body onload="fun()">
<!--onload:加载完文件后的事件-->
<table border="1px" id="tb">
<tr>
<td>123</td>
<td>456</td>
<td>789</td>
</tr>
<tr>
<td>123</td>
<td>456</td>
<td>789</td>
</tr>
<tr>
<td>123</td>
<td>456</td>
<td>789</td>
</tr>
<tr>
<td>123</td>
<td>456</td>
<td>789</td>
</tr>
<tr>
<td>123</td>
<td>456</td>
<td>789</td>
</tr>
</table>
<script>
function fun(){
var a = document.getElementById("tb");
var b = a.rows;//他返回的是一个数组对象
for(var i=1;i<b.length;i++){
var c = b[i];
if(i%2==0){
c.bgColor = "yellow";
}else{
c.bgColor = "red";
}
}
}
</script>
</body>
</html>
9.1表格隔行换色
最新推荐文章于 2020-06-09 14:41:54 发布