帝王谷资源网 Design By www.wdxyy.com
复制代码 代码如下:
/**
* <p>pagination.js
* <p>通用的基于AJAX的分页类
* @author jeanwendy
* @version 1.0
*/
var paginationIndex = 0;
var pagination = function(trTemplatId) {
$().ajaxStart(function() {
$.blockUI({
message : '<table><tr><td style="vertical-align :bottom"><font size=2pt> 加载数据,请稍后...</font></td></tr></table>'
});
}).ajaxStop($.unblockUI);
paginationIndex = paginationIndex + 1;
this.id = paginationIndex;
this.trTemplatId = trTemplatId;
this.pageNo = 1;
this.pageSize = 10;
this.beforeQuery = null;
this.afterQuery = null;
this.url = null;
this.params = null;
this.templat = null;
this.childrenCount = null;
this.setPageNo = function(pageNo) {
if (pageNo != null)
this.pageNo = pageNo;
}
this.setPageSize = function(pageSize) {
if (pageSize != null)
this.pageSize = pageSize;
}
this.setBeforeQuery = function(fn){
this.beforeQuery = fn;
}
this.setAfterQuery = function(fn){
this.afterQuery = fn;
}
this.load = function(url, params) {
//初始化(只在第一次查询时执行)
if(this.templat == null && this.childrenCount == null){
var templatObj = $('#'+this.trTemplatId);
templatObj.parent().attr('id','tbody_id'+this.id);
templatObj.removeAttr('id');
templatObj.wrap("<div id='divTemplat'></div>");
this.templat = $('#divTemplat').html();
$('#divTemplat').remove();
this.childrenCount = $('#tbody_id'+this.id).children().size();
}
//开始查询
this.url = url;
if(params == null) params = {};
$.extend(params,{pageNo:this.pageNo,pageSize:this.pageSize});
this.params = params;
var thisObj = this;
var options = {
url : url,
data : params,
async : false, //采用同步方式请求
type : 'POST',
dataType : 'json',
error : function(xmlhttp, errInfo, e) { //请求出错处理:如:404等
if (xmlhttp.status == 200) alert('您已经很长时间没有访问网站,请退出后重新登陆!');
else alert('请求后台服务时发生错误:' + xmlhttp.status);
},
success : function(data){
//删除上一次的数据
$('#tbody_id'+thisObj.id).children().filter(':gt('+(thisObj.childrenCount-1)+')').remove();
thisObj.pageList(data.data);
thisObj.pageBar(data.total);
if($.isFunction(thisObj.afterQuery)) thisObj.afterQuery();
}
};
if($.isFunction(this.beforeQuery)) this.beforeQuery();
$.ajax(options); //发送请求
}
this.pageList = function(data){
var filedArr = this.templat.match(/\{[A-Za-z0-9_]+\}/ig);
for(var i = 0;i < data.length;i++){
var thisTemplat = this.templat;
for(var j = 0;j < filedArr.length;j++){
var key = filedArr[j].substring(1,filedArr[j].length-1);
if(key == 'NO_'){ //序号标识
var value = (this.pageNo-1)*this.pageSize + i + 1;
thisTemplat = thisTemplat.replace(new RegExp('\{'+key+'\}','gm'),value);
}else{
var value = data[i][key];
if(typeof(value) != "undefined" && value == null) value = '';
thisTemplat = thisTemplat.replace(new RegExp('\{'+key+'\}','gm'),value);
}
}
$(thisTemplat).appendTo($('#tbody_id'+this.id));
}
}
this.pageBar = function(total){
var templatObj = $(this.templat);
var delChildren = templatObj.children(':gt(0)');
delChildren.remove();
templatObj.children().attr('colspan',$(this.templat).children().size());
templatObj.children().attr('align','right');
var pageCount;
if(total % this.pageSize == 0) pageCount = total/this.pageSize;
else pageCount = parseInt(total/this.pageSize) + 1;
if(pageCount == 0) pageCount = 1;
var toolbar = "第"+this.pageNo+"/"+pageCount+"页("+total+"条记录)";
if(this.pageNo == 1) toolbar = toolbar + " 首页 上页";
else toolbar = toolbar + " <a href='' id='firstPage"+this.id+"'>首页</a> <a href='' id='prePage"+this.id+"'>上页</a>";
if(this.pageNo == pageCount) toolbar = toolbar + " 下页 末页";
else toolbar = toolbar + " <a href='' id='nextPage"+this.id+"'>下页</a> <a href='' id='lastPage"+this.id+"'>末页</a>";
toolbar = toolbar + " 每页<input style='text-align:center;width:25px;height:20px;border:1 solid black' type='text' id='pageSize"+this.id+"' value="+this.pageSize+" />条";
toolbar = toolbar + " <input style='text-align:center;width:25px;height:20px;border:1 solid black' type='text' id='pageNo"+this.id+"' value="+this.pageNo+" />";
toolbar = toolbar + " <input style='height:20px;border:1 solid black' id='goPage"+this.id+"' type='button' value='GO'>";
templatObj.children().html(toolbar);
$(templatObj.wrap("<div></div>").parent().html()).appendTo($('#tbody_id'+this.id));
var thisObj = this;
$('#firstPage'+thisObj.id).click(function(){
thisObj.pageNo = 1;
thisObj.load(thisObj.url,thisObj.params);
return false;
});
$('#prePage'+thisObj.id).click(function(){
thisObj.pageNo = parseInt(thisObj.pageNo) - 1;
thisObj.load(thisObj.url,thisObj.params);
return false;
});
$('#nextPage'+thisObj.id).click(function(){
thisObj.pageNo = parseInt(thisObj.pageNo) + 1;
thisObj.load(thisObj.url,thisObj.params);
return false;
});
$('#lastPage'+thisObj.id).click(function(){
thisObj.pageNo = pageCount;
thisObj.load(thisObj.url,thisObj.params);
return false;
});
$('#pageSize'+thisObj.id).keydown(function(e){
if(e.keyCode==13) {
var v = $('#pageSize'+thisObj.id).val();
if(!isIntGreatZero(v) || v == '0'){
alert('您输入显示条数不合法,请重新输入!');
$("#pageSize"+thisObj.id).focus();
return;
}
if(v > 200){
alert('您输入显示条数过大了,请重新输入!');
$("#pageSize"+thisObj.id).focus();
return;
}
thisObj.pageNo = 1;
thisObj.pageSize = v;
thisObj.load(thisObj.url,thisObj.params);
}
});
$('#pageNo'+thisObj.id).keydown(function(e){
if(e.keyCode==13) {
$('#goPage'+thisObj.id).triggerHandler('click');
}
});
$('#goPage'+thisObj.id).click(function(){
var v = $('#pageNo'+thisObj.id).val();
if(!isIntGreatZero(v) || v == '0'){
alert('您输入页数不合法,请重新输入!');
$("#pageNo"+thisObj.id).focus();
return;
}
if(v > pageCount){
alert('您输入页数大于总页数,请重新输入!');
$("#pageNo"+thisObj.id).focus();
return;
}
thisObj.pageNo = v;
thisObj.load(thisObj.url,thisObj.params);
});
}
}
//true if the string is empty
var isEmpty = function(text) {
var isEmpty = true;
for (var i = 0; i < text.length; i++) {
if (text.charAt(i) != ' ') {
isEmpty = false;
break;
}
}
return isEmpty;
}
//true if the string is int and great than zero or equals zero
var isIntGreatZero = function(str) {
if (isEmpty(str))
return false;
var temp1 = true;
var temp2 = '0123456789';
for (var i = 0; i < str.length; i++) {
var c = str.charAt(i);
if (temp2.indexOf(c) == -1) {
temp1 = false;
break;
} else {
if (c == '0' && i == 0 && str.length > 1) {
temp1 = false;
break;
}
}
}
return temp1;
}
/**
* <p>pagination.js
* <p>通用的基于AJAX的分页类
* @author jeanwendy
* @version 1.0
*/
var paginationIndex = 0;
var pagination = function(trTemplatId) {
$().ajaxStart(function() {
$.blockUI({
message : '<table><tr><td style="vertical-align :bottom"><font size=2pt> 加载数据,请稍后...</font></td></tr></table>'
});
}).ajaxStop($.unblockUI);
paginationIndex = paginationIndex + 1;
this.id = paginationIndex;
this.trTemplatId = trTemplatId;
this.pageNo = 1;
this.pageSize = 10;
this.beforeQuery = null;
this.afterQuery = null;
this.url = null;
this.params = null;
this.templat = null;
this.childrenCount = null;
this.setPageNo = function(pageNo) {
if (pageNo != null)
this.pageNo = pageNo;
}
this.setPageSize = function(pageSize) {
if (pageSize != null)
this.pageSize = pageSize;
}
this.setBeforeQuery = function(fn){
this.beforeQuery = fn;
}
this.setAfterQuery = function(fn){
this.afterQuery = fn;
}
this.load = function(url, params) {
//初始化(只在第一次查询时执行)
if(this.templat == null && this.childrenCount == null){
var templatObj = $('#'+this.trTemplatId);
templatObj.parent().attr('id','tbody_id'+this.id);
templatObj.removeAttr('id');
templatObj.wrap("<div id='divTemplat'></div>");
this.templat = $('#divTemplat').html();
$('#divTemplat').remove();
this.childrenCount = $('#tbody_id'+this.id).children().size();
}
//开始查询
this.url = url;
if(params == null) params = {};
$.extend(params,{pageNo:this.pageNo,pageSize:this.pageSize});
this.params = params;
var thisObj = this;
var options = {
url : url,
data : params,
async : false, //采用同步方式请求
type : 'POST',
dataType : 'json',
error : function(xmlhttp, errInfo, e) { //请求出错处理:如:404等
if (xmlhttp.status == 200) alert('您已经很长时间没有访问网站,请退出后重新登陆!');
else alert('请求后台服务时发生错误:' + xmlhttp.status);
},
success : function(data){
//删除上一次的数据
$('#tbody_id'+thisObj.id).children().filter(':gt('+(thisObj.childrenCount-1)+')').remove();
thisObj.pageList(data.data);
thisObj.pageBar(data.total);
if($.isFunction(thisObj.afterQuery)) thisObj.afterQuery();
}
};
if($.isFunction(this.beforeQuery)) this.beforeQuery();
$.ajax(options); //发送请求
}
this.pageList = function(data){
var filedArr = this.templat.match(/\{[A-Za-z0-9_]+\}/ig);
for(var i = 0;i < data.length;i++){
var thisTemplat = this.templat;
for(var j = 0;j < filedArr.length;j++){
var key = filedArr[j].substring(1,filedArr[j].length-1);
if(key == 'NO_'){ //序号标识
var value = (this.pageNo-1)*this.pageSize + i + 1;
thisTemplat = thisTemplat.replace(new RegExp('\{'+key+'\}','gm'),value);
}else{
var value = data[i][key];
if(typeof(value) != "undefined" && value == null) value = '';
thisTemplat = thisTemplat.replace(new RegExp('\{'+key+'\}','gm'),value);
}
}
$(thisTemplat).appendTo($('#tbody_id'+this.id));
}
}
this.pageBar = function(total){
var templatObj = $(this.templat);
var delChildren = templatObj.children(':gt(0)');
delChildren.remove();
templatObj.children().attr('colspan',$(this.templat).children().size());
templatObj.children().attr('align','right');
var pageCount;
if(total % this.pageSize == 0) pageCount = total/this.pageSize;
else pageCount = parseInt(total/this.pageSize) + 1;
if(pageCount == 0) pageCount = 1;
var toolbar = "第"+this.pageNo+"/"+pageCount+"页("+total+"条记录)";
if(this.pageNo == 1) toolbar = toolbar + " 首页 上页";
else toolbar = toolbar + " <a href='' id='firstPage"+this.id+"'>首页</a> <a href='' id='prePage"+this.id+"'>上页</a>";
if(this.pageNo == pageCount) toolbar = toolbar + " 下页 末页";
else toolbar = toolbar + " <a href='' id='nextPage"+this.id+"'>下页</a> <a href='' id='lastPage"+this.id+"'>末页</a>";
toolbar = toolbar + " 每页<input style='text-align:center;width:25px;height:20px;border:1 solid black' type='text' id='pageSize"+this.id+"' value="+this.pageSize+" />条";
toolbar = toolbar + " <input style='text-align:center;width:25px;height:20px;border:1 solid black' type='text' id='pageNo"+this.id+"' value="+this.pageNo+" />";
toolbar = toolbar + " <input style='height:20px;border:1 solid black' id='goPage"+this.id+"' type='button' value='GO'>";
templatObj.children().html(toolbar);
$(templatObj.wrap("<div></div>").parent().html()).appendTo($('#tbody_id'+this.id));
var thisObj = this;
$('#firstPage'+thisObj.id).click(function(){
thisObj.pageNo = 1;
thisObj.load(thisObj.url,thisObj.params);
return false;
});
$('#prePage'+thisObj.id).click(function(){
thisObj.pageNo = parseInt(thisObj.pageNo) - 1;
thisObj.load(thisObj.url,thisObj.params);
return false;
});
$('#nextPage'+thisObj.id).click(function(){
thisObj.pageNo = parseInt(thisObj.pageNo) + 1;
thisObj.load(thisObj.url,thisObj.params);
return false;
});
$('#lastPage'+thisObj.id).click(function(){
thisObj.pageNo = pageCount;
thisObj.load(thisObj.url,thisObj.params);
return false;
});
$('#pageSize'+thisObj.id).keydown(function(e){
if(e.keyCode==13) {
var v = $('#pageSize'+thisObj.id).val();
if(!isIntGreatZero(v) || v == '0'){
alert('您输入显示条数不合法,请重新输入!');
$("#pageSize"+thisObj.id).focus();
return;
}
if(v > 200){
alert('您输入显示条数过大了,请重新输入!');
$("#pageSize"+thisObj.id).focus();
return;
}
thisObj.pageNo = 1;
thisObj.pageSize = v;
thisObj.load(thisObj.url,thisObj.params);
}
});
$('#pageNo'+thisObj.id).keydown(function(e){
if(e.keyCode==13) {
$('#goPage'+thisObj.id).triggerHandler('click');
}
});
$('#goPage'+thisObj.id).click(function(){
var v = $('#pageNo'+thisObj.id).val();
if(!isIntGreatZero(v) || v == '0'){
alert('您输入页数不合法,请重新输入!');
$("#pageNo"+thisObj.id).focus();
return;
}
if(v > pageCount){
alert('您输入页数大于总页数,请重新输入!');
$("#pageNo"+thisObj.id).focus();
return;
}
thisObj.pageNo = v;
thisObj.load(thisObj.url,thisObj.params);
});
}
}
//true if the string is empty
var isEmpty = function(text) {
var isEmpty = true;
for (var i = 0; i < text.length; i++) {
if (text.charAt(i) != ' ') {
isEmpty = false;
break;
}
}
return isEmpty;
}
//true if the string is int and great than zero or equals zero
var isIntGreatZero = function(str) {
if (isEmpty(str))
return false;
var temp1 = true;
var temp2 = '0123456789';
for (var i = 0; i < str.length; i++) {
var c = str.charAt(i);
if (temp2.indexOf(c) == -1) {
temp1 = false;
break;
} else {
if (c == '0' && i == 0 && str.length > 1) {
temp1 = false;
break;
}
}
}
return temp1;
}
标签:
AJAX,分页类
帝王谷资源网 Design By www.wdxyy.com
广告合作:本站广告合作请联系QQ:858582 申请时备注:广告合作(否则不回)
免责声明:本站文章均来自网站采集或用户投稿,网站不提供任何软件下载或自行开发的软件! 如有用户或公司发现本站内容信息存在侵权行为,请邮件告知! 858582#qq.com
免责声明:本站文章均来自网站采集或用户投稿,网站不提供任何软件下载或自行开发的软件! 如有用户或公司发现本站内容信息存在侵权行为,请邮件告知! 858582#qq.com
帝王谷资源网 Design By www.wdxyy.com
暂无评论...
P70系列延期,华为新旗舰将在下月发布
3月20日消息,近期博主@数码闲聊站 透露,原定三月份发布的华为新旗舰P70系列延期发布,预计4月份上市。
而博主@定焦数码 爆料,华为的P70系列在定位上已经超过了Mate60,成为了重要的旗舰系列之一。它肩负着重返影像领域顶尖的使命。那么这次P70会带来哪些令人惊艳的创新呢?
根据目前爆料的消息来看,华为P70系列将推出三个版本,其中P70和P70 Pro采用了三角形的摄像头模组设计,而P70 Art则采用了与上一代P60 Art相似的不规则形状设计。这样的外观是否好看见仁见智,但辨识度绝对拉满。
更新日志
2024年12月26日
2024年12月26日
- 小骆驼-《草原狼2(蓝光CD)》[原抓WAV+CUE]
- 群星《欢迎来到我身边 电影原声专辑》[320K/MP3][105.02MB]
- 群星《欢迎来到我身边 电影原声专辑》[FLAC/分轨][480.9MB]
- 雷婷《梦里蓝天HQⅡ》 2023头版限量编号低速原抓[WAV+CUE][463M]
- 群星《2024好听新歌42》AI调整音效【WAV分轨】
- 王思雨-《思念陪着鸿雁飞》WAV
- 王思雨《喜马拉雅HQ》头版限量编号[WAV+CUE]
- 李健《无时无刻》[WAV+CUE][590M]
- 陈奕迅《酝酿》[WAV分轨][502M]
- 卓依婷《化蝶》2CD[WAV+CUE][1.1G]
- 群星《吉他王(黑胶CD)》[WAV+CUE]
- 齐秦《穿乐(穿越)》[WAV+CUE]
- 发烧珍品《数位CD音响测试-动向效果(九)》【WAV+CUE】
- 邝美云《邝美云精装歌集》[DSF][1.6G]
- 吕方《爱一回伤一回》[WAV+CUE][454M]