jq实现html分页代码,基于jQuery的js分页代码

function pagerBar(dataCount,pageSize,serverUrl,contentPlace,pagerbarPlace,callBack){

this.dataCount = dataCount;

this.pageSize = pageSize;

this.serverUrl = serverUrl;

this.contentPlace = $("#"+contentPlace);

this.pagerbarPlace = $("#"+pagerbarPlace);

this.callBack = callBack;

this.pageCount = 0;

this.pageIndex = 1;

this.curInfo = $("");

this.prePage = $("");

this.nextPage = $("");

this.init();

}

pagerBar.prototype = {

init : function(){

this.getPageCount();

this.initLink();

this.showBarInfo();

if(this.pageCount>0){

this.setLink(1);

}

},

getPageCount : function(){

this.pageCount = parseInt(this.dataCount / this.pageSize);

if(this.dataCount % this.pageSize !=0){

this.pageCount++;

}

},

initLink : function(){

var self = this;

this.prePage = $("").html("上一页").addClass("pageLink");

this.prePage.click(function(){

self.setLink(self.pageIndex-1);

});

this.nextPage = $("").html("下一页").addClass("pageLink");

this.nextPage.click(function(){

self.setLink(self.pageIndex+1);

});

this.pagerbarPlace.append(this.curInfo).append(this.prePage).append(this.nextPage);

},

showBarInfo : function(){

this.prePage.hide();

this.nextPage.hide();

if(this.pageCount==0){

this.curInfo.html("暂时没有信息!");

}

else if(this.pageCount==1){

this.curInfo.html("1/1");

}

else{

this.curInfo.html(this.pageCount + "/" + this.pageIndex);

}

},

setLink : function(i){

var self = this;

$.ajax({

url:self.serverUrl,

type:"get",

data:{pageSize:self.pageSize,pageIndex:i},

cache:false,

error:function(){

alert("数据加载失败!");

},

success:function(htmlData){

self.contentPlace.html(htmlData);

if(self.pageCount==1){

self.prePage.hide();

self.nextPage.hide();

}else{

if(i==1){

self.prePage.hide();

self.nextPage.show();

}else if(i==self.pageCount){

self.prePage.show();

self.nextPage.hide();

}else{

self.prePage.show();

self.nextPage.show();

}

}

self.pageIndex = i;

self.curInfo.html(self.pageCount+"/"+self.pageIndex);

if(self.callBack){

self.callBack();

}

}

});

},

changeServerUrl : function(dataCount,serverUrl){

this.dataCount = dataCount;

this.serverUrl = serverUrl;

this.pageIndex=1;

this.getPageCount();

this.showBarInfo();

this.contentPlace.html("");

if(this.pageCount>0){

this.setLink(1);

}

},

dataCountDec : function(){

this.dataCount--;

this.getPageCount();

if(this.pageCount

this.pageIndex = this.pageCount;

}

if(this.pageIndex>0){

this.setLink(this.pageIndex);

}

this.showBarInfo();

}

}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值