一款Jquery 分页插件的改造方法(服务器端分页)

2020-05-24 21:31:04易采站长站整理

});
$this.find(setting.jumpto$).each(function(){
var $this = $(this);
var $inputBox = $this.find(“:text”);
var $button = $this.find(“:button”);
$button.click(function(event){
var pageNum = $inputBox.val();
if (pageNum && pageNum.isPositiveInteger()) {
PageBreak({ pageNum: pageNum });
}
});
$inputBox.keyup(function(event){
if (event.keyCode == 13) $button.click();
});
});
});
function _bindEvent(jTarget, pageNum, targetType){
jTarget.bind(“click”, {pageNum:pageNum}, function(event){
PageBreak({ pageNum: event.data.pageNum });
event.preventDefault();
});
}
}
var Pagination = function(opts) {
this.opts = $.extend({
targetType:”navTab”, // navTab, dialog
totalCount:0,
numPerPage:10,
pageNumShown:10,
currentPage:1,
callback:function(){return false;}
}, opts);
}
$.extend(Pagination.prototype, {
targetType:function(){return this.opts.targetType},
numPages:function() {
return Math.ceil(this.opts.totalCount/this.opts.numPerPage);
},
getInterval:function(){
var ne_half = Math.ceil(this.opts.pageNumShown/2);
var np = this.numPages();
var upper_limit = np – this.opts.pageNumShown;
var start = this.getCurrentPage() > ne_half ? Math.max( Math.min(this.getCurrentPage() – ne_half, upper_limit), 0 ) : 0;
var end = this.getCurrentPage() > ne_half ? Math.min(this.getCurrentPage()+ne_half, np) : Math.min(this.opts.pageNumShown, np);
return {start:start+1, end:end+1};
},
getCurrentPage:function(){
var currentPage = parseInt(this.opts.currentPage);
if (isNaN(currentPage)) return 1;
return currentPage;
},
hasPrev:function(){
return this.getCurrentPage() > 1;
},
hasNext:function(){
return this.getCurrentPage() < this.numPages();
}
});
})(jQuery);

分页模板pagination.xml:

<?xml version=”1.0″ encoding=”utf-8″?>
<_AJAX_>
<!– pagination –>
<_PAGE_ id=”pagination”><![CDATA[
<ul>
<li class=”j-first”>
<a class=”first” href=”#”><span>首页</span></a>
<span class=”first”><span>首页</span></span>
</li>
<li class=”j-prev”>
<a class=”previous” href=”#”><span>上一页</span></a>
<span class=”previous”><span>上一页</span></span>
</li>
#pageNumFrag#
<li class=”j-next”>
<a class=”next” href=”#”><span>下一页</span></a>
<span class=”next”><span>下一页</span></span>
</li>
<li class=”j-last”>
<a class=”last” href=”#”><span>末页</span></a>