jsp遍历数据库表中的数据(jsp查询数据库数据量)
var data=[
{name:”aa”,age:16,gender:”male”},
{name:”bb”,age:18,gender:”female”},
{name:”cc”,age:19,gender:”male”},
{name:”dd”,age:20,gender:”female”},
];
// 创建表格大概样式
var table=document.createelement(“table”);
var tbody=document.createelement(“tbody”);
var thead=document.createelement(“thead”);
table.appendchild(tbody);
table.appendchild(thead);
var trhead=document.createelement(“tr”);
thead.appendchild(trhead);
// 创建表头
for(var k in data[0]){
var th=document.createelement(“th”);
th.appendchild(document.createtextnode(k));
trhead.appendchild(th)
}
//创建每行的tr和td
for(var i=0;i<data.length;i++){
var tr=document.createelement(“tr”);
for( var k in data[i]){
var td=document.createelement(“td”);
td.appendchild(document.createtextnode(data[i][k]));
tr.appendchild(td);
td.width=”100″;
td.height=”40″;
}
tr.align=”center”;
tbody.appendchild(tr);
}
table.border=”1″;
//加到页面中
document.body.appendchild(table);