创建一个页面,一个按钮,两个输入框
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
</head>
<body>
行:<input type = "text" id="h"/>
列:<input type = "text" id="l"/><br/>
<input type="button" value="生成" onclick="add();"/>
<div id="divv">
</div>
<script type="text/javascript">
function add() {
var h = document.getElementById("h").value;
var l = document.getElementById("l").value;
var tab = "<table border='1' bordercolor='blue'>";
for (var i = 1; i <= h; i++) {
tab+="<tr>";
for (var j = 1; j <= l; j++) {
tab+="<td>aaaaa</td>";
}
tab +="</tr>";
}
tab +="</table>";
var divv= document.getElementById("divv");
divv.innerHTML=tab;
}</script>
</body>
</html>