Xml_javascript分页

2016-02-19 21:44 3 1 收藏

生活已是百般艰难,为何不努力一点。下面图老师就给大家分享Xml_javascript分页,希望可以让热爱学习的朋友们体会到设计的小小的乐趣。

【 tulaoshi.com - Web开发 】

!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(overSize0)
      {
          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;ipageIndex+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(overSize0)
      {
          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;jarr.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;i0;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
  演示:http://home.goofar.com/lkc311/Default.htm

来源:https://www.tulaoshi.com/n/20160219/1626996.html

延伸阅读
标签: Web开发
在网络浏览器软件中,可以Internet Explorer (IE)现在是一种标准的软件。可以看到,运行不同版本的Windows操作系统(和很多其他的操作系统)的每一台机器几乎都使用IE。微软已经通过ActiveX控件将IE的功能包含在执行成熟的XML处理技术中。 在本篇文章中,我们将讲述如何在IE中使用ActiveX功能来访问并解析XML文档,由此允许网络冲浪者操...
标签: Web开发
好久没发过帖子了~~。 因为工作需要,仿豆瓣式写了个分页的样式。 自我感觉,这样的分页前后兼顾,对于用户的体验是蛮好使的。 仿豆瓣分页原型(Javascript版) /* Paginator */ .paginator { font: 14.8px normal Arial, Helvetica, sans-serif; color: #666666; margin-top: 10px; margin-bottom: 5px; line-height: ...
标签: PHP
这是在看太平洋网的评论时看到的,太平洋网是用jsp做为后台语言,用来产生xml文件.然后在把数据绑定到html上的.我就用php也做了一个以下是源文件. -----------------xml.htm------------------ <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd&qu...
标签: Web开发
一.Xml文件 二.IXMLDOMDocument/DOMDocument简介  2.1 属性 2.1.1  parseError  2.1.2  async.  2.1.3  xml  2.1.4  text 3  2.1.5  attributes  2.1.6  nodeName 2.1.7  documentElement  2...
标签: Web开发
动机:  为了方便用户查看大批量数据,我们会用到动态分页,因此分页功能是我们在网站上见过的最普遍也是最常用的一个功能模块了。而以往的信息分页都是连接到数据库的,每一次点击都必须要后台数据库的支持。这样不但服务器的负担加重,而且严重的影响用户浏览的速度.试想,如果把分页的功能放到客户端,那会产生什么样的效果呢...

经验教程

806

收藏

97
微博分享 QQ分享 QQ空间 手机页面 收藏网站 回到头部