日期:2014-05-16 浏览次数:20516 次
function GreenPager(actionPath, params) { ///定义一全局变量,因为分页条那里会使用此变量 greenPager = {};//寄生构造模式(Parasitic Constructor Pattern) greenPager.currentPage = 1; ///当前页号 greenPager.pageCount = 1; ///页总数量 greenPager.pageSize = 15; ///每页显示数量 //中间显示的数字页的数量 greenPager.pageAmount = 3; greenPager.actionPath = actionPath; ///额外的参数 greenPager.params = params; //默认不显示checkbox greenPager.checkboxEnable = false; greenPager.setCheckboxEnable = function(enable) { greenPager.checkboxEnable = enable; } greenPager.go = function(pageNum) { //进度条 if($("#green_pageTable").height()!=0){ $("#green_loadMaskDiv").height($("#green_pageTable").height()); $("#green_loadMaskDiv").width($("#green_pageTable").width()); }else{ $("#green_loadMaskDiv").height(340); $("#green_loadMaskDiv").width(500); } if(pageNum < 1){ pageNum = 1; }else if(pageNum >= this.pageCount){ pageNum = this.pageCount; } var greenPager = this; //分页需要用到的参数及一些查询条件 var pageParams = {'currentPage':pageNum,'pageSize':this.pageSize}; //将params参数放入分页参数中一起提交 if(greenPager.params != undefined){ for(var key in greenPager.params){ pageParams[key] = greenPager.params[key]; } } $.ajax({ type: "get", url: this.actionPath, data: pageParams, cache: false, success: function(data){ data = jQuery.parseJSON(data); //设置当前页数 greenPager.currentPage = pageNum; greenPager.pageCount = data.pageCount; /* 回调 */ greenPager.render(data); greenPager.googlePage(); }, beforeSend: function(){ $("#green_pageTable").hide(); $("#green_loadMaskDiv").fadeIn(60); }, complete: function(){ $("#green_loadMaskDiv").fadeOut(60); $("#green_pageTable").show(); } }); }; greenPager.start = function(){ this.go(this.currentPage); }; greenPager.googlePage = function(){ //谷歌式分页 用来控制数字页及...的显示 var spanPage=""; /*----------------显示上一页-----------------*/ if(greenPager.currentPage==1){ spanPage=spanPage+"<span class='disabled'>? 上一页</span>"; }else{ spanPage=spanPage+"<a class='green_googlePageNum' hidefocus='true' href='javascript:greenPager.go("+(greenPager.currentPage-1)+")'>? 上一页</a>"; } //只有一页 if(greenPager.pageCount==1){ spanPage=spanPage+"<span class='current'>1</span>"; }else if(greenPager.pageCount < greenPager.pageAmount){//页数小于数字显示页数 for(var i=0;i<greenPager.pageAmount;i++){ if(greenPager.currentPage==i){ spanPage=spanPage+"<span class='current'>"+i+"</span>"; }else{ spanPage=spanPage+"<a class='green_googlePageNum' hidefocus='true' href='javascript:greenPager.go("+i+")'>"+(i+1)+"</a>"; } } }else{ //默认始终会显示前面两页,即1,2页 for(var i=1;i<=2;i++){ if(greenPager.currentPage==i){ spanPage=spanPage+"<span class='current'>"+i+"</span>"; }else{ spanPage=spanPage+"<a class='green_googlePageNum' hidefocus='true' href='javascript:greenPager.go("+i+")'>"+i+"</a>"; } } /*------------------ 下面这段代码是重点 ---------------------*/ //从第3页开始显示 var page_start=3; //至倒数第3页结束 var page_end=greenPager.pageCount-3 var v = (greenPager.currentPage - greenPager.pageAmount) > (page_start-1