Html部分
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title></title>
<link rel="stylesheet" type="text/css" href="css/index.css" />
<script src="js/index.js" type="text/javascript" charset="utf-8"></script>
</head>
<body οnlοad="panduan()">
<div id="box1"></div>
<div id="box2">打印 9*9 乘法表<br></div>
</body>
</html>
Css部分
* {
margin: 0;
padding: 0;
}
#box1{
width: 30%;
margin: 100px auto;
text-align: center;
}
#box2{
width: 98%;
margin: 100px auto;
text-align: center;
}
Js部分
function panduan() {
var box1 = document.getElementById('box1');
var box2 = document.getElementById('box2');
var result1 = "";
var result2 = 0;
// 1-100 之间所有数
for (var i = 1; i < 100; i++) {
result1 = result1 + i + '、';
}
result1 = result1 + 100;
// 打印 9*9 乘法表
for (var j = 1; j <= 9; j++) {
for (var k = 1; k <= j; k++) {
result2 = result2+j + ' * ' + k + ' = ' + j * k;
}
box2.innerHTML =box2.innerHTML+result2+'<br/>';
}
box1.innerHTML = '1-100 之间所有数:' + result1;
}