怎样用循环语句编写一个5行4列的表格
1个回答
展开全部
<html>
<head><title>test</title></head>
<style>
.newTable {
width:400px;
height:500px;
border:solid 1px red;
border-collapse:collapse;
text-align:center;
float:left;
}
.newTable td {
width:100px;
height:100px;
border:solid 1px red;
}
</style>
<script type="text/javascript">
function createTable(rows, cols) {
var table = document.createElement("table");
var i;
var j;
table.className = "newTable";
for (i=0;i<rows;i++) {
var tr = table.insertRow();
for (j=0;j<cols;j++) {
var td = tr.insertCell();
td.innerText = "0";
}
}
document.getElementById("content").appendChild(table);
}
</script>
<body>
<input type="button" name="act" value="开始生成" onclick="createTable(5,4);" />
<div id="content">
</div>
</body>
</html>
<head><title>test</title></head>
<style>
.newTable {
width:400px;
height:500px;
border:solid 1px red;
border-collapse:collapse;
text-align:center;
float:left;
}
.newTable td {
width:100px;
height:100px;
border:solid 1px red;
}
</style>
<script type="text/javascript">
function createTable(rows, cols) {
var table = document.createElement("table");
var i;
var j;
table.className = "newTable";
for (i=0;i<rows;i++) {
var tr = table.insertRow();
for (j=0;j<cols;j++) {
var td = tr.insertCell();
td.innerText = "0";
}
}
document.getElementById("content").appendChild(table);
}
</script>
<body>
<input type="button" name="act" value="开始生成" onclick="createTable(5,4);" />
<div id="content">
</div>
</body>
</html>
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询