<style> #output span { display: inline-block; width: 100px; height: 40px; margin: 5px; line-height: 40px; text-align: center; background-color: #ccc; } #output span:hover { background-color: #fc0; color: #fff; } </style> </head> <body> <h1>打印99乘法表</h1> <div id="output"> </div> </body> <script> var output = document.getElementById(‘output‘); var html = ‘‘;//准备存放字符串 for (var i = 1; i <= 9; i++) { //外循环:循环行数 for (var j = 1; j <= i; j++) { //内循环:循环列数 html += ‘<span>‘ + i + ‘x‘ + j + ‘=‘ + i * j + ‘</span>‘; } html += ‘<br />‘; } output.innerHTML = html; </script>
适合刚学js的,锻炼一下逻辑
原文地址:https://www.cnblogs.com/muyun123/p/11404064.html
时间: 2024-10-08 17:50:15