代码如下:
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title></title>
<style type="text/css">
.div01{
width: 100px;
height: 100px;
background-color: #fff;
float: left;
}
.div02{
width: 100px;
height: 100px;
background-color: #000;
float: left;
}
.all{
margin: 0 auto;
width: 800px;
height: 800px;
border: 1px solid #000;
}
</style>
</head>
<body>
<div class="all">
<script>
for(var i=1;i<=8;i++){
for(var j=1;j<=8;j++){
if((i+j)%2==0){
document.write("<div class='div01'></div>");
}
else{
document.write("<div class='div02'></div>");
}
}
}
</script>
</div>
</body>
</html>
运行结果如图: