var node = document.getElementsByTagName("table")[delRow-1]; //表格 var c = node.childNodes.length for(i=0;i<c;i++) node.removeChild(node.childNodes[0]); //删除全部单元行 }
//传入DataSet的一个实例即可 function makeTable(m_ds) {
deleteOldTable() //先清除以前的结果
var table = document.createElement("table"); table.setAttribute("border","1"); table.setAttribute("width","100%");
document.body.appendChild(table); var header = table.createTHead(); var headerrow = header.insertRow(0); headerrow.insertCell(0).appendChild(document.createTextNode("姓名")); headerrow.insertCell(1).appendChild(document.createTextNode("职业")); headerrow.insertCell(2).appendChild(document.createTextNode("工资"));
for(var i=0;i<m_ds.getCount();i++) { var name = m_ds.getAttribute(i,"name") var job = m_ds.getData(i,"job") var salary = m_ds.getData(i,"salary")
var row = table.insertRow(i+1); row.insertCell(0).appendChild(document.createTextNode(name)); row.insertCell(1).appendChild(document.createTextNode(job)); row.insertCell(2).appendChild(document.createTextNode(salary)); } }