不知道为什么表格出不来,求大神帮帮忙?
<!DOCTYPEhtml><htmllang="en"><head><metacharset="UTF-8"><title>Document</title></head...
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Document</title>
</head>
<body>
<h2>请输入表格行列数:</h2>
<table><input id="row" style="width: 50px;" />行
<input id="col" style="width: 50px;"/>列</table>
<input type="button" id="createTable" onclick="createTable()" value="创建"
style="background-color: white; margin-top:20px;"/>
<div id="table" style="border:1px solid;width:100px; height:100px;"></div>
</body>
<script type="text/javascript">
function createTable(){
var table = document.getElementById("table");
var table1 = document.createElement("table");
table.appendChild(table1);
var row = document.getElementById("row").value;
var col = document.getElementById("col").value;
for (var i = 0; i < row; i++) {
var row1=document.createElement("tr");
table.children[0].appendChild(row1);
for (var j = 0; j < col; j++) {
var cpl1=document.createElement("td");
table.children[0].children[i].appendChild(cpl1);
}
}
}
</script>
</html> 展开
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Document</title>
</head>
<body>
<h2>请输入表格行列数:</h2>
<table><input id="row" style="width: 50px;" />行
<input id="col" style="width: 50px;"/>列</table>
<input type="button" id="createTable" onclick="createTable()" value="创建"
style="background-color: white; margin-top:20px;"/>
<div id="table" style="border:1px solid;width:100px; height:100px;"></div>
</body>
<script type="text/javascript">
function createTable(){
var table = document.getElementById("table");
var table1 = document.createElement("table");
table.appendChild(table1);
var row = document.getElementById("row").value;
var col = document.getElementById("col").value;
for (var i = 0; i < row; i++) {
var row1=document.createElement("tr");
table.children[0].appendChild(row1);
for (var j = 0; j < col; j++) {
var cpl1=document.createElement("td");
table.children[0].children[i].appendChild(cpl1);
}
}
}
</script>
</html> 展开
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询