Paginação XML_javascript
Autor:Eve Cole
Data da Última Atualização:2009-07-07 16:22:09
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" " http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd ">
<html xmlns=" http://www.w3.org/1999/xhtml " >
<cabeça>
<title>龙的传人--Xml_javascript分页</title>
</head>
<body onload="getxmlDoc()">
<linguagem script="javascript" type="text/javascript">
var xmlDoc;
var nodeIndex;
var pageIndex;
var pageSize=13;
var últimaPágina; //最后一页
var overSize //最后一页的记录数
função getxmlDoc()
{
xmlDoc=novo ActiveXObject("Microsoft.XMLDOM");
var currNode;
xmlDoc.async=false;
xmlDoc.load("meuTeste.xml");
if(xmlDoc.parseError.errorCode!=0)
{
var meuErr=xmlDoc.parseError;
alert("出错!"+myErr.reason);
}
getRecordCount();
onPrimeiro();
}
função 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;
}
outro
{
lastPage=recordCount-pageSize;
}
}
função getPageRecord(pageIndex,pageSize)
{
clearRow("minhaTabela");
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; //地址
// arr[0]=personNode.childNodes[i].getAttribute("Id"); //序号
// arr[1]=personNode.childNodes[i].childNodes[0].text; //工号
// arr[2]=personNode.childNodes[i].childNodes[1].text; //姓名
// arr[3]=personNode.childNodes[i].childNodes[2].text; //性别
// arr[4]=personNode.childNodes[i].childNodes[3].text; //部门
// arr[5]=personNode.childNodes[i].childNodes[4].text; //职位
// arr[6]=personNode.childNodes[i].childNodes[5].text; //地址
addRow(i+1,"minhaTabela",arr);
}
}
função onFirst()
{
índicePágina=0;
var currIndex=pageIndex;
getPageRecord(currIndex,pageSize)
pageIndex=currIndex;
document.getElementById("txtCurrPage").value=(pageIndex / pageSize) + 1;
document.getElementById("txtCurrPageRecord").value=pageSize;
}
função onPrev()
{
var currIndex=pageIndex;
currIndex-=pageSize;
getPageRecord(currIndex,pageSize)
pageIndex=currIndex;
document.getElementById("txtCurrPage").value=(pageIndex / pageSize) + 1;
document.getElementById("txtCurrPageRecord").value=pageSize;
}
função onNext()
{
var currIndex=pageIndex;
currIndex+=pageSize;
getPageRecord(currIndex,pageSize)
pageIndex=currIndex;
document.getElementById("txtCurrPage").value=(pageIndex / pageSize) + 1;
document.getElementById("txtCurrPageRecord").value=pageSize;
}
função onLast()
{
if(overSize>0)
{
getPageRecord(últimaPágina,overSize)
document.getElementById("txtCurrPageRecord").value=overSize;
}
outro
{
getPageRecord(últimaPágina,pageSize)
document.getElementById("txtCurrPageRecord").value=pageSize;
}
pageIndex=últimaPágina;
document.getElementById("txtCurrPage").value=(pageIndex / pageSize) + 1;
}
função paraPágina()
{
var index=document.getElementById("txtCurrPage").valor
var currIndex=(index-1)*pageSize;
if(evento.keyCode==13)
{
getPageRecord(currIndex,pageSize);
}
pageIndex=currIndex;
}
função addRow(i,dataGridId,arr)
{
var linha=document.createElement("tr");
var cell=createCellWidthText(i);
linha.appendChild(célula);
for(var j=0;j<arr.comprimento;j++)
{
cell=createCellWidthText(arr[j]);
linha.appendChild(célula);
}
document.getElementById(dataGridId).firstChild.appendChild(linha);
}
função criarCellWidthText(texto)
{
var célula = document.createElement("td");
var textNode = document.createTextNode(texto);
cell.appendChild(textNode);
célula de retorno;
}
função limparRow(obj)
{
var tabela=document.getElementById(obj);
var nodeTbody = tabela.firstChild
var comprimento=nodeTbody.childNodes.length;
for(var i=comprimento-1;i>0;i--)
{
nodeTbody.removeChild(nodeTbody.childNodes[i]);
}
}
</script>
<form id="form1" runat="servidor">
<div>
<table align="center" style="border-right: #0033ff sólido fino; borda superior: #0033ff sólido fino;
borda esquerda: #0033ff sólido fino; largura: 650px; borda inferior: #0033ff sólido fino">
<tr>
<td>
共<input id="txtPageCount" name="txtPageCount" style="width: 33px; color: #0000ff; border-top-style: none; border-right-style: none; border-left-style: none; background -cor: transparente; estilo borda inferior: nenhum;" type="text" onkeydown="toPage()"/>页/
<input id="txtRecordCount" name="txtRecordCount" style="largura: 46px; cor: #3300ff; estilo de borda superior: nenhum; estilo de borda direita: nenhum; estilo de borda esquerda: nenhum; fundo- cor: transparente; estilo borda inferior: nenhum;" type="text" onkeydown="toPage()"/>条记录
<input id="btnFirst" type="button" value="首页" onclick="onFirst()"/>
<input id="btnPrev" type="button" value="上一页" onclick="onPrev()"/>
<input id="btnNext" type="button" value="下一页" onclick="onNext()"/>
<input id="btnLast" type="button" value="尾页" onclick="onLast()"/>
第<input id="txtCurrPage" name="txtCurrPage" style="width: 46px; color: #ff3333;" type="text" onkeydown="toPage()"/>
页(当前页<input id="txtCurrPageRecord" name="txtCurrPageRecord" style="width: 22px; color: #ff3333; border-top-style: none; border-right-style: none; border-left-style: nenhum; cor de fundo: branco; estilo de borda inferior: nenhum;" type="text" onkeydown="toPage()"/>条记录)</td>
</tr>
<tr>
<td>
<table width="100%" id="myTable">
<tr style="background-color:Amarelo">
<td style="largura: 34px; altura: 21px;">
ID</td>
<td style="largura: 34px; altura: 21px;">
序号</td>
<td style="largura: 42px; altura: 21px;">
工号</td>
<td style="largura: 36px; altura: 21px;">
姓名</td>
<td style="largura: 39px; altura: 21px;">
性别</td>
<td style="largura: 43px; altura: 21px;">
部门</td>
<td style="largura: 50px; altura: 21px;">
职位</td>
<td style="largura: 100px; altura: 21px;">
地址</td>
</tr>
</tabela>
</td>
</tr>
</tabela>
</div>
</form>
</body>
</html>
Link: http://home.goofar.com/lkc311/Default.htm