salesref.htm

来自「Windows Web脚本开发指南/(美) Dan Heflin, Todd N」· HTM 代码 · 共 40 行

HTM
40
字号
<html>
<script language="JavaScript">
function buildTable(){
  sampleXML.async = false;
  sampleXML.load("salesRef.xml");
  if (sampleXML.parseError != 0) 
    alert(sampleXML.parseError.reason);
  else {
    transactions = sampleXML.selectNodes("//Transaction");
    var transactions;
    var referCustomer;
    var actualCustomer;
    var custID;
    var transaction = transactions.nextNode();
    var tableString = "<table border='1'><thead>";
    tableString += "<th>Customer</th><th>Address</th><th>City</th><th>State</th><th>Amount</th></thead>";
    while (transaction != null){
      referCustomer = transaction.selectSingleNode("referTo:Customer");
      custID = referCustomer.getAttribute("referToID")
      actualCustomer = sampleXML.nodeFromID(custID);
      tempNode = actualCustomer.selectSingleNode("Name");
      tableString += "<tr><td>" + tempNode.text + "</td>";       
      tempNode = actualCustomer.selectSingleNode("Address");
      tableString += "<td>" + tempNode.text + "</td>";       
      tempNode = actualCustomer.selectSingleNode("City");
      tableString += "<td>" + tempNode.text + "</td>";       
      tempNode = actualCustomer.selectSingleNode("State");
      tableString += "<td>" + tempNode.text + "</td>";       
      tempNode = transaction.selectSingleNode("Amount");
      tableString += "<td>" + tempNode.text + "</td></tr>";           
      transaction = transactions.nextNode();
    }
    tableString += "</Table>";
    tableResults.innerHTML = tableString;
  }}</script>
<body onLoad="buildTable()">
<xml ID="sampleXML"></xml>
<div ID="tableResults"></div>
</body></html>

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?