:::info
需求:将九九乘法表打印在页面
:::
代码
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<style>
div {
display: inline-block;
width: 120px;
text-align: center;
border: 1px solid #000;
}
</style>
</head>
<body>
<script>
for (let row = 1; row <= 9; row++) { //行
for (let col = 1; col <= row; col++) {
document.write(`<div> ${col} × ${row}= ${row*col}</div>`)
}
document.write('<br>')
}
</script>
</body>
</html>
效果