<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title></title>
<script type="text/javascript">
function btn(){
var mlie=document.getElementById("lie").value;
var m=parseInt(mlie);
console.log(m);
var mhang=document.getElementById("hang").value;
var h=parseInt(mhang);
console.log(h);
var d=document.getElementById("mdiv");
var mtable=document.createElement("table");
mtable.setAttribute("style","border: 1px solid red;");
for(var i=0;i<m;i++){
var mtr=document.createElement("tr");
for(var j=0;j<h;j++){
var mtd=document.createElement("td");
var child=document.createTextNode(i + "hao" + j);
mtd.appendChild(child);
mtr.appendChild(mtd);
}
mtable.appendChild(mtr);
}
d.appendChild(mtable);
}
function add(){
var tab=document.getElementById("tab");
var tbody=tab.children[0];
console.log(tbody);
}
</script>
</head>
<body>
<label>
<input type="button" value="创建列表" οnclick="btn()" />
</label>
<br />
<label>
列<input type="text" id="lie" />
</label>
<br />
行<label>
<input type="text" id="hang" />
</label>
<input type="button" οnclick="add()" value="添加"/>
<!--<div id="mdiv">
</div>-->
<table id="tab" >
<tr>
<td>姓名</td>
<td>性别</td>
<td>性别x</td>
<td>性别x</td>
</tr>
</table>
</body>
</html>
<html>
<head>
<meta charset="utf-8" />
<title></title>
<script type="text/javascript">
function btn(){
var mlie=document.getElementById("lie").value;
var m=parseInt(mlie);
console.log(m);
var mhang=document.getElementById("hang").value;
var h=parseInt(mhang);
console.log(h);
var d=document.getElementById("mdiv");
var mtable=document.createElement("table");
mtable.setAttribute("style","border: 1px solid red;");
for(var i=0;i<m;i++){
var mtr=document.createElement("tr");
for(var j=0;j<h;j++){
var mtd=document.createElement("td");
var child=document.createTextNode(i + "hao" + j);
mtd.appendChild(child);
mtr.appendChild(mtd);
}
mtable.appendChild(mtr);
}
d.appendChild(mtable);
}
function add(){
var tab=document.getElementById("tab");
var tbody=tab.children[0];
console.log(tbody);
}
</script>
</head>
<body>
<label>
<input type="button" value="创建列表" οnclick="btn()" />
</label>
<br />
<label>
列<input type="text" id="lie" />
</label>
<br />
行<label>
<input type="text" id="hang" />
</label>
<input type="button" οnclick="add()" value="添加"/>
<!--<div id="mdiv">
</div>-->
<table id="tab" >
<tr>
<td>姓名</td>
<td>性别</td>
<td>性别x</td>
<td>性别x</td>
</tr>
</table>
</body>
</html>