javascript

当前位置:首页 > 前端 > javascript

九九乘法表

body { margin-right: 0; padding: 0; font-size: 0 } div { width: 120px; height: 40px; line-height: 40px; text-align: center...

演示链接

body {
	margin-right: 0;
	padding: 0;
	font-size: 0
}

div {
	width: 120px;
	height: 40px;
	line-height: 40px;
	text-align: center;
	color: #fff;
	margin-right: 2px;
	margin-bottom: 2px;
	border-radius: 5px;
	background: #f08080;
	font-size: 16px;
	display: inline-block
}

.wrap {
	height: 100vh;
	overflow: hidden;
	background: #f5f5f5
}

#box,#box2 {
	width: 1157px;
	height: 460px;
	padding: 30px 0 0 30px;
	box-sizing: border-box;
	margin: 454px auto 0;
	position: relative
}
<section class="wrap">
   <section id="box"></section>
</section>

<script>
            var box = document.getElementById('box');

            var colors = ['#78cc64','#58ce7d','#4fcdad','#4cc7dd','#469ee8','#465de8','#5846e8','#8346e8','#9e46e8'];

            var str = '';

            for(var i=1;i<10;i++){
                for(var j=1;j<=i;j++){
                    // console.log(i, j);

                    var text = j + ' * ' + i + ' = ' + j * i;  // 计算里面的数据
                    str += '<div style="background:' + colors[i - 1] + '">' + text + '</div>';
                }

                str += '<br/>';
            }
            
            box.innerHTML = str;

</script>

上一篇:jquery 导航nav下拉

下一篇:JavaScript 教程

相关内容

文章评论

表情

共 0 条评论,查看全部
  • 这篇文章还没有收到评论,赶紧来抢沙发吧~