</head> <body onload="getxmlDoc()"> <script language="Javascript" type="text/javascript"> var xmlDoc; var nodeIndex; var pageIndex; var pageSize=13; var lastPage; //最后一页 var overSize //最后一页的记录数 function getxmlDoc() { xmlDoc=new ActiveXObject("Microsoft.XMLDOM"); var currNode; xmlDoc.async=false; xmlDoc.load("myTest.xml"); if(xmlDoc.parseError.errorCode!=0) { var myErr=xmlDoc.parseError; alert("出错!"+myErr.reason); } getRecordCount(); onFirst();
} function getRecordCount() { var personNode= xmlDoc.selectNodes("/Root")[0]; var recordCount=personNode.childNodes.length; var pageCount=Math.ceil(recordCount/pageSize); document.getElementById("txtPageCount").value=pageCount; document.getElementById("txtRecordCount").value=recordCount; overSize=recordCount%pageSize; if(overSize>0) { lastPage=recordCount-overSize; } else { lastPage=recordCount-pageSize; }
} function getPageRecord(pageIndex,pageSize) { clearRow("myTable"); var personNode= xmlDoc.selectNodes("/Root")[0]; var currNode=personNode.childNodes[pageIndex]; for(var i=pageIndex;i<pageIndex+pageSize;i++) { var arr=new Array(); var nNode= xmlDoc.selectSingleNode("Root/Person["+i+"]") ; arr[0]=nNode.getAttribute("Id"); //序号 arr[1]=nNode.childNodes[0].text; //工号 arr[2]=nNode.childNodes[1].text; //姓名 arr[3]=nNode.childNodes[2].text; //性别 arr[4]=nNode.childNodes[3].text; //部门 arr[5]=nNode.childNodes[4].text; //职位 arr[6]=nNode.childNodes[5].text; //地址