欢迎来到福编程网,本站提供各种互联网专业知识!

用js+xml自动生成表格的东西

发布时间:2006-12-21 作者: 来源:转载
复制代码代码如下:无标题文档functionloadXML(handler){varurl="employees.xml";if(document.implementation&&document.implementation.createDocument){varxmldoc=document.implementation.createDocument("","",null);xmldoc.onload=h
复制代码 代码如下:



无标题文档

functionloadXML(handler){
varurl="employees.xml";
if(document.implementation&&document.implementation.createDocument){
varxmldoc=document.implementation.createDocument("","",null);
xmldoc.onload=handler(xmldoc,url);
xmldoc.load(url);
}
elseif(window.ActiveXObject){
varxmldoc=newActiveXObject("Microsoft.XMLDOM");
xmldoc.onreadystatechange=function(){
if(xmldoc.readyState==4)handler(xmldoc,url);
}
xmldoc.load(url);
}
}
functionmakeTable(xmldoc,url){
vartable=document.createElement("table");
table.setAttribute("border","1");
table.setAttribute("width","600");
table.setAttribute("class","tab-content");
document.body.appendChild(table);
varcaption="EmployeeDatafrom"+url;
table.createCaption().appendChild(document.createTextNode(caption));
varheader=table.createTHead();
varheaderrow=header.insertRow(0);
headerrow.insertCell(0).appendChild(document.createTextNode("姓名"));
headerrow.insertCell(1).appendChild(document.createTextNode("职业"));
headerrow.insertCell(2).appendChild(document.createTextNode("工资"));
varemployees=xmldoc.getElementsByTagName("employee");
for(vari=0;ivare=employees[i];
varname=e.getAttribute("name");
varjob=e.getElementsByTagName("job")[0].firstChild.data;
varsalary=e.getElementsByTagName("salary")[0].firstChild.data;
varrow=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));
}
}






复制代码 代码如下:



Programmer
32768


Sales
70000


CEO
100000


相关推荐