前台JS分页

根据http://hi.baidu.com/fenggandeguozi/blog/item/d8f4ad009fb79f0f1c95835c.html的js前台分页代码,修改一下,加入首页 ,上页,下页,末页的功能。

//页面跳转

 function ready2go(){
    var obj=this;
 
    $("#"+obj.page_obj_id+" a").live("click",function(){ //点击页码的时候跳到相应页  
 alert("obj.cpage:"+obj.cpage);
 
 var tmp = $(this).attr("p");
 if(isNaN(tmp)&&tmp=="next"){
  if((obj.cpage+1)>obj.totalpage){
   obj.target_p=obj.totalpage
  }else{
   obj.target_p=obj.cpage+1;
  }
 }else if(isNaN(tmp)&&tmp=="prev"){
  if((obj.cpage-1)==0){
   obj.target_p=1
  }else{
   obj.target_p=obj.cpage-1;
  }
 }else{
  obj.target_p=parseInt($(this).attr("p"));
 }
    gotopage.call(obj,obj.target_p);
})
}

 

 //生成跳转链接

jsPage.prototype.page=function(){
//alert(this.totalpage);
    if(this.totalpage<=10){        //总页数小于十页   页码以十页为单位
        for (this.count=1;this.count<=this.totalpage;this.count++) {   
   if(this.count!=this.cpage) {
    if(this.count==1){
                    this.outstr = this.outstr + "<a href='javascript:void(0)' p='"+this.count+"' >"+"首页"+"</a>";
     this.outstr = this.outstr + "<a href='javascript:void(0)' p='next' >"+"下页"+"</a>";
     this.outstr = this.outstr + "<a href='javascript:void(0)' p='prev' >"+"上页"+"</a>";
    }else{
     if(this.count==this.totalpage){
      this.outstr = this.outstr + "<a href='javascript:void(0)' p='"+this.count+"' >"+"末页"+"</a>";
     }else{
      this.outstr = this.outstr + "<a href='javascript:void(0)' p='"+this.count+"' >"+this.count+"</a>";
     }
    }
    
            }else{
   //alert(this.outstr);
    if(this.count==1){
     this.outstr = this.outstr + "<span class='current' >"+"首页"+"</span>";
     this.outstr = this.outstr + "<a href='javascript:void(0)' p='next' >"+"下页"+"</a>";
     this.outstr = this.outstr + "<a href='javascript:void(0)' p='prev' >"+"上页"+"</a>";
    }else{
     if(this.count==this.totalpage){
      this.outstr = this.outstr + "<span class='current' >"+"末页"+"</span>";
     }
else{
      this.outstr = this.outstr + "<span class='current' >"+this.count+"</span>";
     }
    }
    
            }
        }
    }

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值