js打印九九乘法表

Scroll Down

js打印九九乘法表(可指定样式)

<div id="table"></div>
    <style>
        ul{
            list-style: none;
        }
        li{
            height: 50px;
        }
        li span{
            display: inline-block;
            width: 90px;
            text-align: center;
            margin-left: 10px;
            padding: 10px 0;
        }
    </style>
    <script>
        let ele = document.getElementById('table');
        function table(num=9,bg='#349178',color='#fff',bor="red"){
            let str = '

';
for (let i = 1; i <= num; i++) {
str+="* ";
for (let j = 1; j <= i; j++) {
str += <span style="background:${bg};color:${color};border: 1px solid ${bor};">${i}*${j}=${i*j}</span>;
}
str += '";
ele.innerHTML +=str;
}
table();