Fork me on GitHub

js经典小案例----乘法表

<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的,锻炼一下逻辑

posted @ 2019-08-24 11:37  幽幽木云  阅读(215)  评论(0编辑  收藏  举报