html
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title></title>
</head>
<body>
<table border="" cellspacing="" cellpadding="">
<tr>
<th id="head" colspan="10">用for循环打印十行十列表格,表格里面写1-100,并且隔列变色</th>
</tr>
<link rel="stylesheet" type="text/css" href="css/question10.css" />
<script src="js/question10.js"></script>
</table>
</body>
</html>
css
.even{
height: 25px;
width: 100px;
background-color: beige;
}
.odd{
height: 25px;
width: 100px;
background-color: gold;
}
js
var count = 1
for(var row = 0; row < 10; row++){
document.write("<tr>")
for(var column = 0; column < 10; column++){
if(!(column%2)){
document.write("<td ")
document.write("id=")
document.write(row,column)
document.write(" class='odd'>")
}else{
document.write("<td ")
document.write("id=")
document.write(row,column)
document.write(" class='even'>")
}
document.write(count)
document.write("</td>")
count++
}
document.write("</tr>")
}
结果图
jsHomework10.png
网友评论