| 加入收藏| 设为首页| 联系我们

首页 站长学习 站长之家 源码下载 建站素材 书籍教程 常用工具
 您现在的位置: 动力中国 >> 网络编程 >> XML教程 >> 文章正文  
 Xml_javascript分页
 

Xml_javascript分页

http://www.domcn.org  文章来源:本站收藏  点击数:

  关键字:Xml_javascript分页

<!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>
                    &nbsp;<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>
演示:http://home.goofar.com/lkc311/Default.htm


Xml_javascript分页
  • 上一篇文章:

  • 下一篇文章:
  •  热门文章
    普通文章 电子邮件改头换面 四公司畅谈未
    普通文章 PC病毒史上最声名狼藉的八大病
    普通文章 Rails系统中的AJAX开发技术简析
    普通文章 基于ASP.NET AJAX框架实现表单
    普通文章 开发ASP.NET AJAX客户端定制行
    普通文章 用JFreeChart对JSP报表进行增强
    普通文章 SQL Server 2005上的CLR和ADO.
    普通文章 SQL Server 2005的XML支持机制
    普通文章 Firefox中标签式浏览技巧大全
    普通文章 Tomcat中的Session和Cookie大揭
     
     推荐文章
    推荐文章 把Google地图嵌入网页 就是这么
    推荐文章 迅雷搜索候选资源出错的解决
    推荐文章 轻松去除迅雷里的各种广告和资
    推荐文章 突破限制 免费领养到QQ空间五级
    推荐文章 Rational统一过程RUP贴近中小软
    推荐文章 构建自己的轻量级XML DOM分析程
    推荐文章 WPS Office 2007技巧:妙用配置
    推荐文章 Excel 2007:求余数函数实用进阶
    推荐文章 浅谈ASP.NET的Postback
    推荐文章 软件开发中项目需求管理简述
     
     相关文章
    没有相关文章
    设为首页 | 加入收藏 | 广告合作 | 联系站长 | 版权申明 |
    动力中国为网友提供免费学习资料,可用资源,如果您认为我们的相关内容侵害到了您的权利请联系管理员
    Copyright © 2006-2008 domcn.org All Rights Reserved.