<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>while</title>
</head>
<body>
<script type="text/javascript">
document.write('<h1>奇数列变为红色</h1>')
var a = 1;
document.write('<table border="3"border-color: cadetblue; font-size: 25px;"')
while (a < 10){
console.log(a);
document.write('</tr>')
var b = 1;
while (b < 10){
if(b % 2 != 0){
document.write('<td style="background-color: red;">' + a + '*' + b + '=' + a * b + '</td>')
}else{
document.write('<td>' + a + '*' + b + '=' + a * b + '</td>');
}
b ++;
}
document.write('</tr>')
a ++;
}
document.write('</table>')
document.write('<h1>奇数行变为红色</h1>')
var a = 1;
document.write('<table border="3">')
while (a < 10){
document.write('<tr>')
var b = 1;
while( b < 10 ){
if(a % 2 != 0 ){
document.write('<td style="background-color: red;">' + b + '*' + a + '=' + a * b + '</td>')
}else{
document.write('<td>' + b + '*' + a + '=' + a * b + '</td>');
}
b ++;
}
document.write('</tr>')
a ++;
}
document.write('</table>')
document.write('<h1>奇数行奇数列变为红色</h1>')
var a = 1;
document.write('<table border="3">')
while (a < 10){
document.write('<tr>')
var b = 1;
while( b < 10 ){
if(a % 2 != 0 && b % 2 == 1 || a % 2 == 0 && b % 2 == 0){
document.write('<td style="background-color: red;">' + b + '*' + a + '=' + a * b + '</td>')
}else{
document.write('<td>' + b + '*' + a + '=' + a * b + '</td>');
}
b ++;
}
document.write('</tr>')
a ++;
}
document.write('</table>')
document.write('<h1>81右下</h1>')
var a = 1;
document.write('<table style=" color: darkslateblue;">')
while (a < 10){
document.write('<tr>')
var b = 1;
while( b < 10 ){
if(b <= a){
document.write('<td style="text-indent: 20px;">' + b + '*' + a + '=' + a * b + '</td>')
}
b ++;
}
document.write('</tr>')
a ++;
}
document.write('</table>')
document.write('<h1>81左下</h1>')
var a = 1;
document.write('<table style=" color: darkslateblue;">')
while (a < 10){
document.write('<tr>')
var b = 1;
while( b < 10 ){
if(a <= b){
document.write('<td style="text-indent: 20px;">' + b + '*' + a + '=' + a * b + '</td>')
}
b ++;
}
document.write('</tr>')
a ++;
}
document.write('</table>')
document.write('<h1>81右上</h1>')
var a = 9;
document.write('<table style=" color: darkslateblue;">')
while (a >= 0){
document.write('<tr>')
var b = 1;
while( b < 10){
if(b <= a){
document.write('<td style="text-indent: 20px;">' + b + '*' + a + '=' + a * b + '</td>')
}
b ++;
}
document.write('</tr>')
a --;
}
document.write('</table>')
</script>
</body>
</html>