/** *================================================================= *name: 叶子js分页样式(showopage style with js) *rcsfile: cls_jspage.js *revision: 0.06beta *author: yehe(叶子) *released: 2005-04-26 13:11:42 *description: js分页样式,显示上一页下一页的翻页结果 *contact: qq:311673,msn:myehe@msn.com *website: http://www.yehe.org,http://www.showo.com *================================================================= */ function cls_jspage(ireccount,ipagesize,ipagenum,sname){ this.irc=cls_jspage.fformatnum(ireccount,1,0,0,0);//总记录条数 this.ips=cls_jspage.fformatnum(ipagesize,1,0,1,0);//每页记录数目 this.ipn=cls_jspage.fformatnum(ipagenum,0,0,0,0);//显示的前后页数,0为显示所有,负数为这么多页面一个跳转 this.sn=sname;//实例对象名 this.stpage="{$page}";//页数 this.stpagecount="{$pagecount}";//总页数 this.streccount="{$reccount}";//总记录数 this.stpagesize="{$pagesize}";//每页记录数 this.stpagefrist="{$pagefrist}";//首页 this.stpageprev="{$pageprev}";//上页 this.stpagenext="{$pagenext}";//下页 this.stpagelast="{$pagelast}";//尾页 this.stpagetext="{$pagetext}";//数字跳转 this.stpagetextf="{$pagetextf}";//数字跳转框架 this.stpageinput="{$pageinput}";//输入框跳转 this.stpageselect="{$pageselect}";//下拉菜单跳转 this.stpagenum="{$pagenum}";//数字页数 this.ipc=this.getpagecount();//得到页数 } //输入 页数开始值,结尾值 cls_jspage.prototype.setpagese=function(spagestart,spageend){ var sps=spagestart,spe=spageend; this.sps=(sps.length>0)?sps:"page="; this.spe=(spe.length>0)?spe:""; } //输入 网址 cls_jspage.prototype.seturl=function(surl){ var s=surl; this.url=(s.length>0)?s:""+document.location; } //输入 输入框&下拉框name值 cls_jspage.prototype.setpageinput=function(spageinput){ var spi=spageinput; this.spi=(spi.length>0)?spi:"page"; } //输入 语言 首页(disable,enale) cls_jspage.prototype.setpagefrist=function(sdis,sen){ var sd=sdis,se=sen; this.pf_d=sd; this.pf_e=se; } //输入 语言 上页 cls_jspage.prototype.setpageprev=function(sdis,sen){ var sd=sdis,se=sen; this.pp_d=sd; this.pp_e=se; } //输入 语言 下页 cls_jspage.prototype.setpagenext=function(sdis,sen){ var sd=sdis,se=sen; this.pn_d=sd; this.pn_e=se; } //输入 语言 尾页 cls_jspage.prototype.setpagelast=function(sdis,sen){ var sd=sdis,se=sen; this.pl_d=sd; this.pl_e=se; } //输入 语言 数字跳转 cls_jspage.prototype.setpagetext=function(sdis,sen){ var sd=sdis,se=sen; this.pt_d=sd;//"[{$pagenum}]" this.pt_e=se;//"第{$pagenum}页" } //输入 语言 数字跳转外围模板 cls_jspage.prototype.setpagetextf=function(sdis,sen){ var sd=sdis,se=sen; this.ptf_d=sd;//" {$pagetextf} " this.ptf_e=se;//" {$pagetextf} " } //输入 语言 下拉菜单跳转 cls_jspage.prototype.setpageselect=function(sdis,sen){ var sd=sdis,se=sen; this.ps_d=sd;//"[{$pagenum}]" this.ps_e=se;//"第{$pagenum}页" } //输入 css cls_jspage.prototype.setpagecss=function(scsspagetext,scsspageinput,scsspageselect){ var scpt=scsspagetext,scpi=scsspageinput,scps=scsspageselect; this.cpt=scpt;//数字跳转css this.cpi=scpi;//输入框跳转css this.cps=scps;//下拉菜单跳转css } //输入 html模板 cls_jspage.prototype.sethtml=function(shtml){ var sh=shtml; this.html=sh;//html模板 } //计算页数 cls_jspage.prototype.getpagecount=function(){ var irc=this.irc,ips=this.ips,i=0; i=(irc%ips==0)?(irc/ips):(cls_jspage.fformatnum((irc/ips),1,0,0,0)+1); return (i); } //取得模板页数和当前页数 cls_jspage.prototype.geturl=function(itype){ var s=this.url,sps=this.sps,spe=this.spe,stp=this.stpage,ipc=this.ipc; var it=itype; var i,spageindex; if (s.indexof(sps)==-1) { s+=(s.indexof("?")==-1)?"?"+sps+stp:"&"+sps+stp; //s=cls_jspage.freg(su,"(&+)","&"); //s=cls_jspage.freg(su,"(\?&)","\?"); i=1; } else { sreg="(\\s.*)"+cls_jspage.fformatreg(sps)+"(\\d*)"+cls_jspage.fformatreg(spe)+"(\\s.*|\\s*)"; spageindex=cls_jspage.freg(s,sreg,"$3"); s=s.replace(sps+spageindex+spe,sps+stp+spe); i=cls_jspage.fformatnum(spageindex,1,1,0,ipc); } return (it==0?s:i) } //页面跳转 cls_jspage.prototype.pagejump=function(){ var spl,spv,sp; var su=this.geturl(0),ipi=this.geturl(1); var spi=this.spi,stp=this.stpage,ipc=this.ipc; eval("spl=document.getelementsbyname(\""+spi+"\").length;"); if (spl>1) { for (i=0;i0) { location.href(su.replace(stp,sp)); break; } } } else { eval("spv=document.all."+spi+".value;"); sp=cls_jspage.fformatnum(spv,1,1,0,ipc); if (sp>0&&(sp!=ipi)) { location.href(su.replace(stp,sp)); } } } //输出 cls_jspage.prototype.write=function(){ var su=this.geturl(0),ipi=this.geturl(1); var sn=this.sn,spi=this.spi; var ipc=this.ipc,ipn=this.ipn;; var irc=this.irc,ips=this.ips; var pf_d=this.pf_d,pf_e=this.pf_e; var pp_d=this.pp_d,pp_e=this.pp_e; var pn_d=this.pn_d,pn_e=this.pn_e; var pl_d=this.pl_d,pl_e=this.pl_e; var pt_d=this.pt_d,pt_e=this.pt_e; var ptf_d=this.ptf_d,ptf_e=this.ptf_e; var ps_d=this.ps_d,ps_e=this.ps_e; var cpt=this.cpt,cpi=this.cpi; var cps=this.cps,ipn=this.ipn; var s=this.html; stpage=this.stpage; stpagecount=this.stpagecount; streccount=this.streccount; stpagesize=this.stpagesize; stpfrist=this.stpagefrist; stpprev=this.stpageprev; stpnext=this.stpagenext; stplast=this.stpagelast; stptext=this.stpagetext; stptextf=this.stpagetextf; stpinput=this.stpageinput; stpselect=this.stpageselect; stpagenum=this.stpagenum; prevp=cls_jspage.fformatnum((ipi-1),1,1,1,ipc); nextp=cls_jspage.fformatnum((ipi+1),1,1,1,ipc); if (ipi<=1&&ipc<=1) { firstpu=pf_d; prevpu=pp_d; nextpu=pn_d; lastpu=pl_d; } else if (ipi==1&&ipc>1) { firstpu=pf_d; prevpu=pp_d; nextpu=""+pn_e+""; lastpu=""+pl_e+""; } else if (ipi==ipc) { firstpu=""+pf_e+""; prevpu=""+pp_e+""; nextpu=pn_d; lastpu=pl_d; } else { firstpu=""+pf_e+""; prevpu=""+pp_e+""; nextpu=""+pn_e+""; lastpu=""+pl_e+""; } pageselect=""; pagetext=""; pageinput=""; if (ipn<0) { ipn=math.abs(ipn); pagestart=(ipi%ipn==0)?(ipi/ipn):(cls_jspage.fformatnum((ipi/ipn),1,0,0,0)); pagestart=(pagestart*ipn==ipi)?((pagestart-1)*ipn+1):(pagestart*ipn+1); pageend=cls_jspage.fformatnum(pagestart+ipn,0,1,0,ipc) } else if (ipn==0) { pagestart=1; pageend=ipc; } else { pagestart=cls_jspage.fformatnum((ipi-ipn),1,0,1,0); pageend=cls_jspage.fformatnum((pagestart+ipn*2),0,1,0,ipc); pagestart=(pageend==ipc)?cls_jspage.fformatnum((pageend-ipn*2),1,0,1,0):pagestart; } if (ipc>=1) { pageselect=""; for (i=pagestart;i<=pageend;i++) { if (i!=ipi) { xx=""+pt_e.replace(stpagenum,i)+""; pagetext+=ptf_e.replace(stptextf,xx); pageselect+=""; } else { xx=""+pt_d.replace(stpagenum,i)+""; pagetext+=ptf_d.replace(stptextf,xx); pageselect+=""; } } pageselect+=""; } s=s.replace(stpage,ipi); s=s.replace(stpagecount,ipc); s=s.replace(streccount,irc); s=s.replace(stpagesize,ips); s=s.replace(stpfrist,firstpu); s=s.replace(stpprev,prevpu); s=s.replace(stpnext,nextpu); s=s.replace(stplast,lastpu); s=s.replace(stptext,pagetext); s=s.replace(stpinput,pageinput); s=s.replace(stpselect,pageselect); document.write (s); } //输出html代码 cls_jspage.prototype.gethtml=function(){ var su=this.geturl(0),ipi=this.geturl(1); var sn=this.sn,spi=this.spi; var ipc=this.ipc,ipn=this.ipn;; var irc=this.irc,ips=this.ips; var pf_d=this.pf_d,pf_e=this.pf_e; var pp_d=this.pp_d,pp_e=this.pp_e; var pn_d=this.pn_d,pn_e=this.pn_e; var pl_d=this.pl_d,pl_e=this.pl_e; var pt_d=this.pt_d,pt_e=this.pt_e; var ptf_d=this.ptf_d,ptf_e=this.ptf_e; var ps_d=this.ps_d,ps_e=this.ps_e; var cpt=this.cpt,cpi=this.cpi; var cps=this.cps,ipn=this.ipn; var s=this.html; stpage=this.stpage; stpagecount=this.stpagecount; streccount=this.streccount; stpagesize=this.stpagesize; stpfrist=this.stpagefrist; stpprev=this.stpageprev; stpnext=this.stpagenext; stplast=this.stpagelast; stptext=this.stpagetext; stptextf=this.stpagetextf; stpinput=this.stpageinput; stpselect=this.stpageselect; stpagenum=this.stpagenum; prevp=cls_jspage.fformatnum((ipi-1),1,1,1,ipc); nextp=cls_jspage.fformatnum((ipi+1),1,1,1,ipc); if (ipi<=1&&ipc<=1) { firstpu=pf_d; prevpu=pp_d; nextpu=pn_d; lastpu=pl_d; } else if (ipi==1&&ipc>1) { firstpu=pf_d; prevpu=pp_d; nextpu=""+pn_e+""; lastpu=""+pl_e+""; } else if (ipi==ipc) { firstpu=""+pf_e+""; prevpu=""+pp_e+""; nextpu=pn_d; lastpu=pl_d; } else { firstpu=""+pf_e+""; prevpu=""+pp_e+""; nextpu=""+pn_e+""; lastpu=""+pl_e+""; } pageselect=""; pagetext=""; pageinput=""; if (ipn<0) { ipn=math.abs(ipn); pagestart=(ipi%ipn==0)?(ipi/ipn):(cls_jspage.fformatnum((ipi/ipn),1,0,0,0)); pagestart=(pagestart*ipn==ipi)?((pagestart-1)*ipn+1):(pagestart*ipn+1); pageend=cls_jspage.fformatnum(pagestart+ipn,0,1,0,ipc) } else if (ipn==0) { pagestart=1; pageend=ipc; } else { pagestart=cls_jspage.fformatnum((ipi-ipn),1,0,1,0); pageend=cls_jspage.fformatnum((pagestart+ipn*2),0,1,0,ipc); pagestart=(pageend==ipc)?cls_jspage.fformatnum((pageend-ipn*2),1,0,1,0):pagestart; } if (ipc>=1) { pageselect=""; for (i=pagestart;i<=pageend;i++) { if (i!=ipi) { xx=""+pt_e.replace(stpagenum,i)+""; pagetext+=ptf_e.replace(stptextf,xx); pageselect+=""; } else { xx=""+pt_d.replace(stpagenum,i)+""; pagetext+=ptf_d.replace(stptextf,xx); pageselect+=""; } } pageselect+=""; } s=s.replace(stpage,ipi); s=s.replace(stpagecount,ipc); s=s.replace(streccount,irc); s=s.replace(stpagesize,ips); s=s.replace(stpfrist,firstpu); s=s.replace(stpprev,prevpu); s=s.replace(stpnext,nextpu); s=s.replace(stplast,lastpu); s=s.replace(stptext,pagetext); s=s.replace(stpinput,pageinput); s=s.replace(stpselect,pageselect); return s; } //输入:欲格式化字符,是否有最小值(0表示没有,1表示有),是否有最大值,最小值(默认值),最大值 cls_jspage.fformatnum=function(snum,bmin,bmax,iminnum,imaxnum){ var i,in,itmin,itmax,sn=""+snum,bmi=bmin,bma=bmax,imin=iminnum,imax=imaxnum; if (sn.length>0) { in=parseint(sn,10); i=(isnan(in))?imin:in; i=(iimax&&bma==1)?imax:i; } else { i=imin; } return (i); } //输入:欲正则字符,正则表达式,替换后字符 cls_jspage.freg=function(sstr,sreg,sre){ var s="",ss=sstr,sr=sreg,sre=sre; if ((ss.length>0)&&(sr.length>0)) { eval("re=/"+sr+"/gim;"); s=ss.replace(re,sre); } return (s); } //格式化正则中的特殊字符 cls_jspage.fformatreg=function(sreg){ var s="",sr=sreg; var sf=new array ("/",".","+","[","]","{","}","$","^","?","*"); if (sr.length>0) { for (i=0;i<=sf.length;i++) { sr=sr.replace(sf[i],"\\"+sf[i]); } s="("+sr+")"; } return (s); }