th,td {
border:solid 1px black;
width:100px;
}
-->
</style>
<script type="text/javascript" >
function color() {
//把表头设为紫色
var th = document.getElementById("th");
th.style.background = "violet"
//1.得到所有<tr>元素
var trs = document.getElementsByTagName("tr");
var i;
for(i = 1; i <trs.length; i++) {
//2.改变<tr>元素的背景颜色
if(i % 2 == 0) {
trs[i].style.background = "yellow";
} else {
trs[i].style.background = "olive";
}
}
}
window.onload = color;
</script>
</head>
<body>
<center>
<table>
责任编辑:cyth