<!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" >
<head>
<title>龙的传人--Xml_javascript分页</title>
</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; //地址
// 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,"myTable",arr);
}
}
function onFirst()
{
pageIndex=0;
var currIndex=pageIndex;
getPageRecord(currIndex,pageSize)
pageIndex=currIndex ;
document.getElementById("txtCurrPage").value=(pageIndex / pageSize) + 1;
document.getElementById("txtCurrPageRecord").value=pageSize;
}
function onPrev()
{
var currIndex=pageIndex;
currIndex-=pageSize;
getPageRecord(currIndex,pageSize)
pageIndex=currIndex;
document.getElementById("txtCurrPage").value=(pageIndex / pageSize) + 1;
document.getElementById("txtCurrPageRecord").value=pageSize;
}
function onNext()
{
var currIndex=pageIndex;
currIndex+=pageSize;
getPageRecord(currIndex,pageSize)
pageIndex=currIndex;
document.getElementById("txtCurrPage").value=(pageIndex / pageSize) + 1;
document.getElementById("txtCurrPageRecord").value=pageSize;
}
function onLast()
{
if(overSize>0)
{
getPageRecord(lastPage,overSize)
document.getElementById("txtCurrPageRecord").value=overSize;
}
else
{
getPageRecord(lastPage,pageSize)
document.getElementById("txtCurrPageRecord").value=pageSize;
}
pageIndex=lastPage;
document.getElementById("txtCurrPage").value=(pageIndex / pageSize) + 1;
}
function toPage()
{
var index=document.getElementById("txtCurrPage").value
var currIndex=(index-1)*pageSize;
if(event.keyCode==13)
{
getPageRecord(currIndex,pageSize);
}
pageIndex=currIndex;
}
function addRow(i,dataGridId,arr)
{
var row=document.createElement("tr");
var cell=createCellWidthText(i);
row.appendChild(cell);
for(var j=0;j<arr.length;j++)
{
cell=createCellWidthText(arr[j]);
row.appendChild(cell);
}
document.getElementById(dataGridId).firstChild.appendChild(row);
}
function createCellWidthText(text)
{
var cell = document.createElement("td");
var textNode = document.createTextNode(text);
cell.appendChild(textNode);
return cell;
}
function clearRow(obj)
{
var table=document.getElementById(obj);
var nodeTbody=table.firstChild
var length=nodeTbody.childNodes.length;
for(var i=length-1;i>0;i--)
{
nodeTbody.removeChild(nodeTbody.childNodes[i]);
}
}
</script>
<form id="form1" runat="server">
<div>
<table align="center" style="border-right: #0033ff thin solid; border-top: #0033ff thin solid;
border-left: #0033ff thin solid; width: 650px; border-bottom: #0033ff thin solid">
<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-color: transparent; border-bottom-style: none;" type="text" onkeydown="toPage()"/>页/
<input id="txtRecordCount" name="txtRecordCount" style="width: 46px; color: #3300ff; border-top-style: none; border-right-style: none; border-left-style: none; background-color: transparent; border-bottom-style: none;" 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: none; background-color: white; border-bottom-style: none;" type="text" onkeydown="toPage()"/>条记录)</td>
</tr>
<tr>
<td>
<table width="100%" id="myTable">
<tr style="background-color:Yellow">
<td style="width: 34px; height: 21px;">
Id</td>
<td style="width: 34px; height: 21px;">
序号</td>
<td style="width: 42px; height: 21px;">
工号</td>
<td style="width: 36px; height: 21px;">
姓名</td>
<td style="width: 39px; height: 21px;">
性别</td>
<td style="width: 43px; height: 21px;">
部门</td>
<td style="width: 50px; height: 21px;">
职位</td>
<td style="width: 100px; height: 21px;">
地址</td>
</tr>
</table>
</td>
</tr>
</table>
</div>
</form>
</body>
</html>
分享到:
相关推荐
JS的滑动门读取不同的XML并分页.
XML+Javascript 实现静态页搜索及分页功能
主要介绍了javascript读取xml数据对其实现javascript分页效果,大家参考使用吧
通用的分页代码。稍微修改就可以拉。他是js加xml实现的。你也可以改成其他的。实例可以使用
基于web的技术中,分页是一个老的不能再老的,但大家津津乐道的问题,随着xml技术的日渐应用,把xml应用到分页当中,也是一种可能,当然网上的教程很多,当我都是看得稀里糊涂,索性自己写一个,与大家分享、指正。
/music_admin/index....XML分页技术,加快了网页的浏览速度,翻页效率。 JS参数传递,实现无跳页播放,让大家体现真正的“流畅”。后台目录名随意改。 =================================== 附:HTML FLA PSD 源码
基于cefsharp开发的爬虫,使用xml和javascript配置,解决了分页的问题 开发环境: visual studio 2017 .net framework 4.5.2 c#
对xml+xsl实现分页排序的改进,使支持对所有数据进行排序 以往见过的利用xml+xsl来实现分页排序的基本都只能本页内排序,而不能对所有数据进行排序,究其原因,简单分析如下: xml+xsl分页原理:在xsl中,遍历节点...
JavaScript与xml结合的实例,实现分页技术!
用javascript做的一个中学语文学习的小项目,主要用到javascript操作xml,javascript实现分页,javascript和html脚本实现图片拖拽
Asp+AJAX静态分页 亲测 可用 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html> <head> <meta ...
XML 代码部分 这是一个新闻的XML 文件,如果 NBody部分包含 XML 和Html 不可识别部分, 就 包含在DATA 表示附中。
severlet jsp 分页 ajax等技术的笔记
XML分页技术,加快了网页的浏览速度,翻页效率。 JS参数传递,实现无跳页播放,让大家体现真正的“流畅”。后台目录名随意改。 =================================== 附:HTML FLA PSD 源码 请到 ...
xml+html+javascript
实例355 用JavaScript控制XML文档的分页显示 565 实例356 通过操作XML数据岛实现添加、删除留言信息 567 第15章 JavaScript与ASP结合 573 15.1 弹出窗口/对话框控制 574 实例357 关闭弹出窗口时刷新父窗口...
text javascript"> var currpage <% request getParameter "cntPage" %>; 记录当前页面 $ document ready function { 初始化列表 initGrid ; } ; window dhx ...