通过javascript实现1~100内能同时被2和3整除的数并生成如下表格

  • Post author:
  • Post category:java




请通过javascript实现1~100内能同时被2和3整除的数并生成如下表格;






<!DOCTYPE html>

<html lang=”en”>

<head>

<meta charset=”UTF-8″>

<title>Document</title>

<style type=”text/css”>

html{height:100%;}

body{margin:0;height:100%;text-align: center;background: #F9F9E0;}

#box{height:100%;display: -webkit-box;-webkit-box-pack:center;-webkit-box-align:center;}

table{border-collapse:collapse;}

th,td{padding:0;}

td{border: 1px solid #429fff; width:150px;height:50px;}

</style>

<script type=”text/javascript”>

window.onload = function(){


var oBox = document.getElementById(‘box’);

var str = ”;

var num = 0;

str+=”<table>”;

for (var i = 1; i <= 100; i++) {


if ( i%6 == 0 ) {


num++;

if (num%4 == 1) {


str += “<tr>”;

}

str += “<td>”+i+”</td>”;

if (num%4 == 0) {


str += “</tr>”;

};

};

};

str += “</table>”;

oBox.innerHTML = str;

}

</script>

</head>

<body>

<div id=”box”>

</div>

</body>

</html>

转载于:https://www.cnblogs.com/jiechen/p/4976218.html