jq实现html分页代码,基于jQuery的js分页代码function pagerBar(dataCount,pageSize,serverUrl,contentPlace,pagerbarPlace,callBack){
this.dataCount = dataCount;
this.pageSize = pageSize;
this.serverUrl = serverUrl;
this.pagerbarPlace = $("#"+pagerbarPlace);
this.callBack = callBack;
this.pageCount = 0;
this.pageIndex = 1;
this.curInfo = $("");
this.prePage = $("");
this.init();
}
pagerBar.prototype = {
init : function(){
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);
});
self.setLink(self.pageIndex+1);
});
this.pagerbarPlace.append(this.curInfo).append(this.prePage).Page); },
showBarInfo : function(){
this.prePage.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){
if(self.pageCount==1){
self.prePage.hide();
}else{
if(i==1){
self.prePage.hide();
}else if(i==self.pageCount){
jquery免费特效下载
self.prePage.show();
}else{
self.prePage.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.showBarInfo();
if(this.pageCount>0){
this.setLink(1);
}
},
dataCountDec : function(){
this.dataCount--;
if(this.pageCount
this.pageIndex = this.pageCount; }
if(this.pageIndex>0){
this.setLink(this.pageIndex);
}
this.showBarInfo();
}
}

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。