:::info 需求:将九九乘法表打印在页面 :::

代码

  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="UTF-8">
  5. <meta http-equiv="X-UA-Compatible" content="IE=edge">
  6. <meta name="viewport" content="width=device-width, initial-scale=1.0">
  7. <title>Document</title>
  8. <style>
  9. div {
  10. display: inline-block;
  11. width: 120px;
  12. text-align: center;
  13. border: 1px solid #000;
  14. }
  15. </style>
  16. </head>
  17. <body>
  18. <script>
  19. for (let row = 1; row <= 9; row++) { //行
  20. for (let col = 1; col <= row; col++) {
  21. document.write(`<div> ${col} × ${row}= ${row*col}</div>`)
  22. }
  23. document.write('<br>')
  24. }
  25. </script>
  26. </body>
  27. </html>

效果

image.png