关闭

页数显示js

200人阅读 评论(0) 收藏 举报
&nbs

HTML Tags and JavaScript tutorial



页数显示js




function Page(curPage,totalPage,num,sParam)
{
 this.curPage=curPage;
 this.totalPage = totalPage;
 this.num = num;
 this.param = sParam;
 this.curPage=this.curPage<this.totalPage?this.curPage:this.totalPage;
}
Page.prototype.showPage = function()
{
 var sHtml = "";
 var _iStarPage,_iEndPage;
 var _bIsShowPreviousImage=false;
 var _bIsShowNextImage=false;
 if(this.curPage<=1)
  this.curPage=1;
 if(this.totalPage<this.num)
 {
  _iEndPage = this.totalPage;
  _iStarPage = 1;
 }else{
  if(this.curPage<=Math.ceil(this.num/2)){
   _iStarPage = 1;
   _iEndPage = this.num;
   if(this.totalPage-this.curPage>this.num)
    _bIsShowNextImage = true;
  }else if(this.curPage>Math.ceil(this.num/2)&&this.curPage<(this.totalPage-parseInt(this.num/2))){
   _iStarPage = this.curPage-Math.ceil(this.num/2)+1;
   _iEndPage = this.curPage+parseInt(this.num/2);
   if(this.curPage-this.num>1)
    _bIsShowPreviousImage=true;
   if(this.totalPage-this.curPage>this.num)
    _bIsShowNextImage = true;
  }else if(this.curPage>=(this.totalPage-parseInt(this.num/2))){
   _iStarPage = this.totalPage-this.num+1;
   _iEndPage = this.totalPage;
   if(this.curPage-this.num>1)
    _bIsShowPreviousImage=true;
  }
 }
 //sHtml ="<table cellpadding=/"0/" cellspacing=/"0/" border=/"0/">";
 //sHtml +="<tr>";
 sHtml +="<span style=/"width:25px;/"><a href=?"+this.param+"&page=1 title=/"首页/"><img src=/"/images/First.gif/" border=/"0/" align=/"absbottom/"></a></span>"
 if(_bIsShowPreviousImage==true)
  sHtml +="<span style=/"width:25px;/"><a href=?"+this.param+"&page="+(this.curPage-this.num)+" title=/"前"+this.num+"页/"><img src=/"/images/previous.gif/" border=/"0/" align=/"absbottom/"></a></span>"
 for(var i=_iStarPage;i<=_iEndPage;i++)
 {
  if(this.curPage==i){
   sHtml += "<span style=/"width:25px;/"><a href=?"+this.param+"&page="+i+"><font color=/"#ff0000/"><b>"+i+"</b></font></a></span>";
  }else{
   sHtml += "<span style=/"width:25px;/"><a href=?"+this.param+"&page="+i+"><b>"+i+"</b></a></span>";
  }
 }
 if(_bIsShowNextImage==true)
  sHtml +="<span style=/"width:25px;/"><a href=?"+this.param+"&page="+(this.curPage+this.num)+" title=/"后"+this.num+"页/"><img src=/"/images/next.gif/" border=/"0/" align=/"absbottom/"></a></span>"
 sHtml +="<span style=/"width:25px;/"><a href=?"+this.param+"&page="+this.totalPage+" title=/"尾页/"><img src=/"/images/Last.gif/" border=/"0/" align=/"absbottom/"></a></span>"
 //sHtml +="</tr></table>";
 document.write(sHtml);



p;
0
0

查看评论
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
    个人资料
    • 访问:152464次
    • 积分:4043
    • 等级:
    • 排名:第7956名
    • 原创:242篇
    • 转载:0篇
    • 译文:0篇
    • 评论:16条
    文章存档
    最新评论