JavaScript简单生成表格,巩固基础知识点。。。
<!DOCTYPE html>
<html>
<head>
<title>JavaScript简单生成表格</title>
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<script type="text/javascript" >
function create()
{
var h=document.getElementById("t1").value;
var l=document.getElementById("t2").value;
var table="<table border='1' bordercolor='red'>";
for(var i=0;i<h;i++)
{
table+="<tr>";
for(var j=0;j<l;j++)
table+="<td>詹姆斯</td>";
table+="</tr>";
}
table+="</table>"
document.getElementById("div1").innerHTML=table;
}
</script>
</head>
<body>
行:<input type="text" id="t1"/>
列:<input type="text" id="t2"/><br><br>
<input type="button" value="生成" onclick="create();">
<div id="div1"></div>
</body>
</html>
运行示意:
aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAAAf4AAADMCAIAAAAdyFZgAAALkklEQVR4nO3dO5Mc1RkG4PMvFCogcKhwMxTiTKFCQiWUQdwEkUOF2NzEpQoFGKuICBUqs7h6AQVEsAYh5LIQK2xkRdY42NrRzHSf093TM9195jxPTU3N9HT3vjV1vle9s7ulMAOgMGHsAAAMTfUDFEf1AxRH9QMUR/UDFEf1AxRn0Or/ED78cMgl18fY7xOTMPYy3JZo9Yew+X8Vdvh9pKXh18DaK9lyZYfXQHP1hzrrfbEdfh9pabNroHZxrqxPy5W17fAaqJ+KbVzyz3b6faSlLa2BxIpV/axth9dAzVRsqfdnO/0+0tJg1b/4bet657Rc2eE1sPmBSZi/jw/2Lz25dzKEcPKJp68ebPzrMF3bmKXaT3s2Wf3XLy6c/syV270Tk4mCqv/RC9ur/sOr506cuXzwYDabHV67cGrv0jcb/0pM1Zaqv/p4g9V/+8qZM1cO1s9Htoqr/vTPeNf+SW/d+3jtQjj7kcuoYmx8lmI/1N1g9e9fPHHh+rr5yFlZ1R9r9v7fB1TexwcHV86e1PwlybD6b3909vTlg3XzkbOCqv9oTgap/usX9/ZOhr0L1w57npaMbPyXO2eRlt9c9e9fPHH67JNP+NlUgUqp/vS0xEao/ec/Ne/j4bULp/Yu7j9oczg7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