XML DOM 百分网手机站

js+xml自动生成表格的代码

时间:2018-04-19 09:12:49 XML DOM 我要投稿

js+xml自动生成表格的代码

  复制代码 代码如下:

  

  

  

  无标题文档

  

  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.Row(0);

  headerrow.Cell(0).appendChild(document.createTextNode("姓名"));

  headerrow.Cell(1).appendChild(document.createTextNode("职业"));

  headerrow.Cell(2).appendChild(document.createTextNode("工资"));

  varemployees=xmldoc.getElementsByTagName("employee");

  for(vari=0;i<employees.length;i++){

  vare=employees[i];

  varname=e.getAttribute("name");

  varjob=e.getElementsByTagName("job")[0].firstChild.data;

  varsalary=e.getElementsByTagName("salary")[0].firstChild.data;

  varrow=table.Row(i+1);

  row.Cell(0).appendChild(document.createTextNode(name));

  row.Cell(1).appendChild(document.createTextNode(job));

  row.Cell(2).appendChild(document.createTextNode(salary));

  }

  }

  

  

  

  

  

  

  复制代码 代码如下:

  

  

  

  Programmer

  32768

  

  

  Sales

  70000

  

  

  CEO

  100000

  

  

【js+xml自动生成表格的代码】相关文章:

1.jQuery的合并表格中相同文本的相邻单元格的代码

2.怎么自动生成图表目录

3.jQuery实现的拖动调整表格单元格的大小代码实例

4.Excel表格的必学技巧

5.excel表格的修复方法

6.Excel表格的求和方法

7.excel表格的创建

8.word的自动生成目录如何操作