本文实例讲述了js分页工具的用法。分享给大家供大家参考。具体实现方法如下:
js代码部分:
(function(){
var Page = {version:"1.0",author:"liuxingmi"};
var showPage = 9;
Page.navigation = function(divId,totalRecord,totalPage,currentPage,func){
var nav = '<ul class=\"pagination\" title=\"分页列表\">';
nav += '<li class="totalAnnal">总记录数:<i id="totalRecord">' + totalRecord +'';
nav += '<li class="totalPage">总页数:<i id="totalPage">' + totalPage + '';
nav += '<li class="currentPage">当前页:<b id="pageNum">' + currentPage + '';
if(currentPage == 1){
nav += '<li class="firstPage currentState"><a href="javascript:void(0);" id="firstPage" title="首页">首页';
nav += '<li class="previousPage currentState"><a href="javascript:void(0);" id="frontPage" title="前一页">前一页';
} else {
nav += '<li class="firstPage"><a href="javascript:' + func + '(1);" id="firstPage" title="首页">首页';
nav += '<li class="previousPage"><a href="javascript:' + func + '('+ (currentPage -1) +');" id="frontPage" title="前一页">前一页';
}
nav += '<li id="num">
- ';
- <a title="转到第1页" href="javascript:' + func + '(' + i + ');">' + i + ' ';
var start = currentPage - Math.floor(showPage/2);
var end = currentPage + Math.floor(showPage/2);
if(end > totalPage){
start -= (end - totalPage);
}
if(start <= 0){
start = 1;
}
if(currentPage < showPage && end < showPage){
end = showPage;
}
if(end > totalPage){
end = totalPage;
}
for(var i = start; i <= end; i++){
if(i == currentPage){
nav += '<li class="currentState"><a title="转到第1页" href="javascript:' + func + '(' + i + ');">' + i + '';
} else {
nav += '
}
}
nav += '
if(currentPage == totalPage){
nav += '<li class="nextPage currentState"><a href="javascript:void(0);" id="nextPage" title="后一页">后一页';
nav +='<li class="lastPage currentState"><a href="javascript:void(0);" id="lastPage" title="尾页">尾页';
} else {
nav += '<li class="nextPage"><a href="javascript:' + func + '('+ (currentPage + 1) +');" id="nextPage" title="后一页">后一页';
nav +='<li class="lastPage"><a href="javascript:' + func + '(' + totalPage + ');" id="lastPage" title="尾页">尾页';
}
nav += '';
$("#" + divId).html(nav);
};
this.Page = Page;
})();
css部分:
调用方法:
希望本文所述对大家的javascript程序设计有所帮助。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。