JavaScript案例七:简单生成表格
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>
运行示意: