大雀软件园

首页 软件下载 安卓市场 苹果市场 电脑游戏 安卓游戏 文章资讯 驱动下载
技术开发 网页设计 图形图象 数据库 网络媒体 网络安全 站长CLUB 操作系统 媒体动画 安卓相关
当前位置: 首页 -> 技术开发 -> Script -> 用数据岛生成翻页程序

用数据岛生成翻页程序

时间: 2021-07-31 作者:daque

<html>

<head><title>tree walk test - jscript</title><style>body         { font-family: 宋体; font-size: 9pt }.first       { color: gray; text-decoration: none }.later       { cursor: hand; color: red; text-decoration: none }</style><meta name="generator" content="microsoft frontpage 4.0"><meta name="progid" content="frontpage.editor.document"></head>

<!--摆设证明:width遏制当前线的宽窄;sortby排序指向底下的data的tagname;sorttype为排序典型,暂时扶助三种:text,date,number,也可实行本人的典型,只有窜改sort因变量就可了--><xml id="head"><xmldata>  <username width="150" sortby="username" sorttype="text">用户名</username>  <pw width="150" sortby="pw" sorttype="number">暗号</pw>  <date width="200" sortby="date" sorttype="date">日子</date></xmldata></xml><!--摆设证明:isshow,遏制此处实质能否表露;iskey能否是主键,1是且实质会在thevalue内里表露,0否;--><xml id="data"><xmldata><row>  <id isshow="0" iskey="1">1</id>  <username isshow="1" iskey="1">fmzhang1</username>  <pw       isshow="1" iskey="1">1</pw>  <date     isshow="1" iskey="0">2003-3-3</date></row><row>  <id isshow="0" iskey="1">2</id>  <username isshow="1" iskey="1">fmzhang11</username>  <pw       isshow="1" iskey="1">1</pw>  <date     isshow="1" iskey="0">2003-3-3</date></row><row>  <id isshow="0" iskey="1">3</id>  <username isshow="1" iskey="1">fmzhang2</username>  <pw       isshow="1" iskey="1">2</pw>  <date     isshow="1" iskey="0">2003-3-7</date></row><row>  <id isshow="0" iskey="1">4</id>  <username isshow="1" iskey="1">fmzhang3</username>  <pw       isshow="1" iskey="1">3</pw>  <date     isshow="1" iskey="0">2003-5-3</date></row><row>  <id isshow="0" iskey="1">5</id>  <username isshow="1" iskey="1">fmzhang4</username>  <pw       isshow="1" iskey="1">4</pw>  <date     isshow="1" iskey="0">2002-3-3</date></row><row>  <id isshow="0" iskey="1">6</id>  <username isshow="1" iskey="1">fmzhang5</username>  <pw       isshow="1" iskey="1">5</pw>  <date     isshow="1" iskey="0">2003-1-3</date></row><row>  <id isshow="0" iskey="1">7</id>  <username isshow="1" iskey="1">fmzhang6</username>  <pw       isshow="1" iskey="1">6</pw>  <date     isshow="1" iskey="0">2005-1-3</date></row><row>  <id isshow="0" iskey="1">8</id>  <username isshow="1" iskey="1">fmzhang7</username>  <pw       isshow="1" iskey="1">7</pw>  <date     isshow="1" iskey="0">2003-5-3</date></row><row>  <id isshow="0" iskey="1">9</id>  <username isshow="1" iskey="1">fmzhang8</username>  <pw       isshow="1" iskey="1">8</pw>  <date     isshow="1" iskey="0">2003-1-8</date></row><row>  <id isshow="0" iskey="1">10</id>  <username isshow="1" iskey="1">fmzhang9</username>  <pw       isshow="1" iskey="1">9</pw>  <date     isshow="1" iskey="0">2003-11-3</date></row></xmldata></xml><body id="objbody" onload="show('first')">

<div id="mydiv"></div><table border="0" cellpadding="2" width="57%">  <tr>    <td width="13%"><input type="button" value="首页" onclick="show('first')"></td>    <td width="14%"><input type="button" value="上一页" onclick="show('prov')"></td>    <td width="35%"><input type="button" value="下一页" onclick="show('next')"></td>    <td width="14%"><input type="button" value="结果一页" onclick="show('last')"></td>    <td width="40%"><input type="text" size="5" maxlength="5" name="pagenum" value onkeydown="if(event.keycode==13) gopagenum()" onkeyup="value=value.replace(/[^\d]/g,'')" onblur="value=value.replace(/[^\d]/g,'')" onbeforepaste="clipboarddata.setdata('text',clipboarddata.getdata('text').replace(/[^\d]/g,''))"><input type="button" value="go" onclick="gopagenum()"></td>  </tr>  <tr>    <td width="13%">用户名</td>    <td width="14%"><input type="text" name="xm" size="10" value></td>    <td width="35%" nowrap onclick="if(isresult.checked==true) isresult.checked=false;else if(isresult.checked==false) isresult.checked=true"><input type="checkbox" name="isresult" onclick="if(this.checked==true) this.checked=false;else this.checked=true;" value="on">在暂时截止中搜索</td>    <td width="54%" colspan="2"><input type="button" name="search" onclick="search()" value="搜索" size="10"></td>  </tr></table><table border="0" cellpadding="2" width="100%"></table>    <table id="tablesec">  <tr>    <td>      <!--       增添本人的按钮    -->      <input type="button" value="此处增添自设置按钮" onclick="yourfunction()"></td>  </tr></table>

</body>

</html><script>//底下为初始化参数 var datanodes=data.documentelement.childnodes; //底下三行生存复本,供简略此后回复 var xmldoc=document.all("data").xmldocument; var xmldoctemp=new activexobject("msxml.domdocument"); xmldoctemp.appendchild(xmldoc.documentelement.clonenode(true));  var totalrow=datanodes.length;//总额据行数 var pagerow=4;//每页行数 var totalpage=0;//总页数 if(totalrow!=0) {   if(totalrow%pagerow!=0) totalpage=parseint(totalrow/pagerow)+1;   else totalpage=parseint(totalrow/pagerow); } var currpage=1;//暂时页码 var checkarr=new array();//能否选中 var thevaluearr=new array();//记载选中记载的checkbox的value值 for(var i=0;i<totalrow;i++) {   checkarr[i]=0;//记载选中的记载0为未选中,1为选中,初始为0   thevaluearr[i]=""; } var buildarr=new array();//生存暂时页要天生的记载序号 var sortorder='asce';//生存叶序仍旧降序   mydiv.innertext="所有"+totalpage+"页"+totalrow+"条记载,暂时为第1页,暂时选中0条记载"; var nodes=head.documentelement.childnodes; var nodeslen=nodes.length; var attributes=head.documentelement.firstchild.attributes; var objform=document.createelement("<form name='fjcl'>"); var objtable=document.createelement("<table bordercolor='#1ec600' border='1'>");  var objtbody=document.createelement("tbody"); objtable.appendchild(objtbody);</script><script language="javascript">//天生表格头部function addhead(){ var objtr=document.createelement("<tr  bgcolor='#ffcccc'>"); objtbody.appendchild(objtr); var objtd=document.createelement("td"); objtd.width="20"; objtd.innertext=" "; objtr.appendchild(objtd); for(var i=0;i<nodeslen;i++) {   var objtd=document.createelement("<td onclick='' onmousemove=''>");   objtd.width=head.documentelement.childnodes.item(i).getattribute("width");   objtd.onmousemove="style.cursor='hand'";   var sortby=head.documentelement.childnodes.item(i).getattribute("sortby");   var sorttype=head.documentelement.childnodes.item(i).getattribute("sorttype");   objtd.onclick="sort('"+sortby+"','"+sorttype+"','"+i+"')";   var tdtext=nodes.item(i).text+"→";   var objtext=document.createtextnode(tdtext);   objtd.appendchild(objtext);   objtr.appendchild(objtd); } objform.appendchild(objtable); objbody.appendchild(objform); objbody.appendchild(tablesec);}//增添适合前提的记载function addall(){  var childdatanodes=data.documentelement.childnodes.item(0).childnodes;  var childtotalrow=childdatanodes.length;//每行底下大概的数据项长度  for(var i=0;i<buildarr.length;i++)  {        var objtr;    if(i%2==0)    {        objtr=document.createelement("<tr onmouseover='' bgcolor='#80ff80'  class='first' onclick='changecolor()' >");    }else    {       objtr=document.createelement("<tr onmouseover='' bgcolor='#ffff80'  class='first' onclick='changecolor()' >");    }    if(checkarr[buildarr[i]-1]==1) objtr.classname="later";    objtr.onmouseover="style.cursor='hand'";    var thetd=document.createelement("td");    var objcheckbox;    if(checkarr[buildarr[i]-1]==0)     {      objcheckbox=document.createelement("<input type='checkbox' name='rad' value='' onclick=''>");    }else    {      objcheckbox=document.createelement("<input type='checkbox' name='rad' value='' onclick='' checked>");    }        objcheckbox.onclick=objcheckbox.onclick+";if(this.checked==true) checkarr["+parseint(buildarr[i]-1)+"]='1';else checkarr["+parseint(buildarr[i]-1)+"]=0";    thetd.appendchild(objcheckbox);    objtr.appendchild(thetd);    for(var j=0;j<childtotalrow;j++)    {      var isshow=datanodes.item(buildarr[i]-1).childnodes.item(j).getattribute("isshow");//能否表露      var iskey=datanodes.item(buildarr[i]-1).childnodes.item(j).getattribute("iskey");  //能否是主键      if(isshow=='1')//isshow=1      {         var objtd=document.createelement("<td onclick=''>");         var tdtext=document.createtextnode(datanodes.item(buildarr[i]-1).childnodes.item(j).text);         objtd.appendchild(tdtext);         objtr.appendchild(objtd);                   objtd.onclick=objcheckbox.click;      }      if(iskey=='1')      {         if(objcheckbox.value=="")             objcheckbox.value=objcheckbox.value+datanodes.item(buildarr[i]-1).childnodes.item(j).tagname+"="+datanodes.item(buildarr[i]-1).childnodes.item(j).text;         else              objcheckbox.value=objcheckbox.value+"&"+datanodes.item(buildarr[i]-1).childnodes.item(j).tagname+"="+datanodes.item(buildarr[i]-1).childnodes.item(j).text;      }    }    thevaluearr[buildarr[i]-1]=objcheckbox.value;    objtbody.appendchild(objtr);  }  objform.appendchild(objtable);  objbody.appendchild(objform);  objbody.appendchild(tablesec);}//翻页按钮操纵function show(thepage){  if(totalrow==0)  {   del();   addhead();   return false;   }  if(thepage=="first")  {    del();    addhead();     buildarr=new array();    if(totalrow>=pagerow){       for(var i=1;i<=pagerow;i++)          buildarr[i-1]=i;    }else{       for(var i=1;i<=totalrow;i++)          buildarr[i-1]=i;    }    addall();    currpage=1;  }else if(thepage=="prov")  {    if(currpage==1) return false;    del();    addhead();    buildarr=new array();    for(var i=1;i<=pagerow;i++){      buildarr[i-1]=(currpage-2)*pagerow+i;    }    addall();    currpage=currpage-1;  }else if(thepage=="next")  {    if(currpage==totalpage) return false;    del();    addhead();    buildarr=new array();    if((currpage+1)*pagerow>=totalrow){       for(var i=1;i<=totalrow-currpage*pagerow;i++)          buildarr[i-1]=currpage*pagerow+i;    }else {      for(var i=1;i<=pagerow;i++)          buildarr[i-1]=currpage*pagerow+i;    }     addall();    currpage=currpage+1;  }else if(thepage=="last")  {    if(currpage==totalpage) return false;     del();    addhead();    buildarr=new array();    if(totalrow%pagerow==0){      for(var i=1;i<=pagerow;i++)         buildarr[i-1]=totalrow-pagerow+i;    }else{      for(var i=1;i<=totalrow%pagerow;i++)         buildarr[i-1]=totalrow-totalrow%pagerow+i;    }    addall();    currpage=totalpage;  }  changemydiv();}//简略objform底下的一切实质function del(){ objform.removenode(true); objform=document.createelement("<form name='fjcl'>"); objtable=document.createelement("<table bordercolor='#1ec600' border='1'>");  objtbody=document.createelement("tbody"); objtable.appendchild(objtbody);}//变换脸色function changecolor(){ for(var i=0;i<objtbody.childnodes.length-1;i++) {   var therow=buildarr[i]-1;   if(checkarr[therow]==0)   {     objtbody.childnodes.item(i+1).classname="first";   }   else   {     objtbody.childnodes.item(i+1).classname="later";   }   } changemydiv();}function changemydiv(){ var totalchecked=0;//记载暂时选中记载数 for(var i=0;i<totalrow;i++) {   if(checkarr[i]==1) totalchecked+=1; } mydiv.innertext="所有"+totalpage+"页"+totalrow+"条记载,暂时为第"+currpage+"页,暂时选中"+totalchecked+"条记载"; }

function showvalue(){  var str="";  var str2="";  for(var i=0;i<totalrow;i++)  {    str+=checkarr[i]+";";    if(checkarr[i]==1) str2+=thevaluearr[i]+";";  }  alert(str);  alert(str2);}//跳转到某个页function gopagenum(){  var page=pagenum.value;  if(totalrow==0)  {    alert("没有可操纵的记载!");    return false;  }  if(page.length==0)  {     alert("请输出要跳转的页码!");     return false;  }  if(parseint(page)==0||parseint(page)>totalpage)  {    alert("输出页码应介于1和"+totalpage+"之间!");    return false;  }   if(page==currpage) return false;    if(page==1)  {    show('first');  }else if(page==totalpage)  {    show('last');  }else  {    del();    addhead();    buildarr=new array();    for(var i=0;i<pagerow;i++){      buildarr[i]=(page-1)*pagerow+i+1;    }    addall();    currpage=page;  }  changemydiv();}function yourfunction(){  if(totalrow==0)  {    alert("没有可操纵的记载!");    return false;  }  var totalchecked=0;//记载暂时选中记载数  for(var i=0;i<totalrow;i++)  {    if(checkarr[i]==1) totalchecked+=1;  }  if(totalchecked==0)  {    alert("没有选中记载,请采用保守行操纵!");    return false;  }  var pk='';  for(var i=0;i<totalrow;i++)  {    if(checkarr[i]==1)      pk+=thevaluearr[i]+";";  }  alert(pk);  <!--  //  此处增添你要的操纵  -->}</script><script>//以次实行对各别数据典型举行排序//比拟两个字符串function compare_text(text1,text2){  if(text1>text2) return 1;  else return 0;}//比拟两个数字的巨细(按浮点数)function compare_number(number1,number2){  if(parsefloat(number1)>parsefloat(number2)) return 1;  else return 0;}//比拟两个日子的巨细function compare_date(kssj,jssj){  var kssjarr=kssj.split("-");  var jssjarr=jssj.split("-");  var date1=new date(kssjarr[0],kssjarr[1],kssjarr[2]);  var date2=new date(jssjarr[0],jssjarr[1],jssjarr[2]);  if(date1>date2) return 1;  else return 0;}</script><script>//点击排序按钮时实行此因变量function sort(sortby,sorttype,sortnum){if(data.documentelement.childnodes.length==0) return false;  var sortbyarr=new array();  for(var i=0;i<buildarr.length;i++){    sortbyarr[i]=datanodes.item(buildarr[i]-1).getelementsbytagname(sortby).item(0).text;  }    if(sortorder=='asce') {   //叶序    for(var i=0;i<buildarr.length;i++){       for(var j=0;j<buildarr.length-1;j++){         var temparr;         var tempsort;         if(sorttype=='text'){             if(compare_text(sortbyarr[j],sortbyarr[j+1])==1){                 temparr=sortbyarr[j];sortbyarr[j]=sortbyarr[j+1];sortbyarr[j+1]=temparr;                 tempsort=buildarr[j];buildarr[j]=buildarr[j+1];buildarr[j+1]=tempsort;             }         }else if(sorttype=='number'){             if(compare_number(sortbyarr[j],sortbyarr[j+1])==1){                 temparr=sortbyarr[j];sortbyarr[j]=sortbyarr[j+1];sortbyarr[j+1]=temparr;                 tempsort=buildarr[j];buildarr[j]=buildarr[j+1];buildarr[j+1]=tempsort;             }         }else if(sorttype=='date'){             if(compare_date(sortbyarr[j],sortbyarr[j+1])==1){                temparr=sortbyarr[j];sortbyarr[j]=sortbyarr[j+1];sortbyarr[j+1]=temparr;                 tempsort=buildarr[j];buildarr[j]=buildarr[j+1];buildarr[j+1]=tempsort;             }         }       }    }    sortorder="desc";  } else if(sortorder=='desc'){  //降序    for(var i=0;i<buildarr.length;i++){       for(var j=0;j<buildarr.length-1;j++){         var temparr;         var tempsort;         if(sorttype=='text'){             if(compare_text(sortbyarr[j],sortbyarr[j+1])==0){                temparr=sortbyarr[j];sortbyarr[j]=sortbyarr[j+1];sortbyarr[j+1]=temparr;                 tempsort=buildarr[j];buildarr[j]=buildarr[j+1];buildarr[j+1]=tempsort;             }         }else if(sorttype=='number'){             if(compare_number(sortbyarr[j],sortbyarr[j+1])==0){                temparr=sortbyarr[j];sortbyarr[j]=sortbyarr[j+1];sortbyarr[j+1]=temparr;                 tempsort=buildarr[j];buildarr[j]=buildarr[j+1];buildarr[j+1]=tempsort;             }         }else if(sorttype=='date'){             if(compare_date(sortbyarr[j],sortbyarr[j+1])==0){                temparr=sortbyarr[j];sortbyarr[j]=sortbyarr[j+1];sortbyarr[j+1]=temparr;                 tempsort=buildarr[j];buildarr[j]=buildarr[j+1];buildarr[j+1]=tempsort;             }         }       }    }    sortorder="asce";  }    del();    addhead();    addall();    if(sortorder=="asce"){       objtable.rows[0].cells[parseint(sortnum)+1].innertext=nodes.item(parseint(sortnum)).text+"↓";    }else{       objtable.rows[0].cells[parseint(sortnum)+1].innertext=nodes.item(parseint(sortnum)).text+"↑";    }}//在原有截止中搜索时也简略data的一切node,而后把xmldoctemp的一切node复制到data内里function delallnode(){  var len=datanodes.length;  for(var i=0;i<len;i++)  {    datanodes.item(i).parentnode.removechild(datanodes.item(i));    i-=1;    len-=1;  }}//此因变量实行在截止中搜索适合前提的记载function search(){  if(isresult.checked==false)  {    delallnode();    var xmldoctemplen=xmldoctemp.documentelement.childnodes.length;    for(var i=0;i<xmldoctemplen;i++)    {       data.documentelement.appendchild(xmldoctemp.documentelement.childnodes.item(i).clonenode(true));        }    datanodes=data.documentelement.childnodes;     }  var nodelen=datanodes.length;  for(var i=0;i<nodelen;i++)  {    if(!isshow(i)) //不适合前提的简略    {      datanodes.item(i).parentnode.removechild(datanodes.item(i));      i-=1;      nodelen-=1;    }  }  totalrow=datanodes.length;//总额据行数 totalpage=0;//总页数 if(totalrow!=0) {   if(totalrow%pagerow!=0) totalpage=parseint(totalrow/pagerow)+1;   else totalpage=parseint(totalrow/pagerow); } currpage=1;//暂时页码 checkarr=new array();//能否选中 thevaluearr=new array();//记载选中记载的checkbox的value值 for(var i=0;i<totalrow;i++) {   checkarr[i]=0;//记载选中的记载0为未选中,1为选中,初始为0   thevaluearr[i]=""; } buildarr=new array();//生存暂时页要天生的记载序号 sortorder='asce';//生存叶序仍旧降序  mydiv.innertext="所有"+totalpage+"页"+totalrow+"条记载,暂时为第1页,暂时选中0条记载"; show('first');}//底下这个因变量须要你本人实行,适合前提的记载(要表露)归来true,要不归来falsefunction isshow(nodeno){

  var myxm=xm.value;  var temp=datanodes.item(nodeno).getelementsbytagname("username");  if(temp.item(0).text.indexof(myxm)!=-1) return true;  return false;

}</script>

热门阅览

最新排行

Copyright © 2019-2021 大雀软件园(www.daque.cn) All Rights Reserved.