Jquery dynamically generates the table sample code

  • 2020-03-30 01:05:14
  • OfStack

 
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" 
"http://www.w3.org/TR/html4/loose.dtd"> 
<html> 
<head> 
<meta http-equiv="Content-Type" content="text/html; charset=gb2312"> 
<title> Dynamic table creation </title> 
<script type="text/javascript" src="Scripts/jquery-1.3.2.js"></script> 
<script type="text/javascript"> 
function CreateTable(rowCount,cellCount) 
{ 
var table=$("<table border="1">"); 
table.appendTo($("#createtable")); 
for(var i=0;i<rowCount;i++) 
{ 
var tr=$("<tr></tr>"); 
tr.appendTo(table); 
for(var j=0;j<cellCount;j++) 
{ 
var td=$("<td>"+i*j+"</td>"); 
td.appendTo(tr); 
} 
} 
trend.appendTo(table); 
$("#createtable").append("</table>"); 
} 
</script> 
</head> 

<body> 
<input type="button" value=" Add form " onClick="CreateTable(5,6)" > 
<input type="button" value=" Add the line "> 
<div id="createtable"></div> 
<div id="createrow"></div> 
</body> 
</html> 

Related articles: