js分页工具实例

复制代码 代码如下:

/** 
 * 分页js 
 */ 
var Page; 
 
(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>总记录数:<i>' + totalRecord +'</i></li>'; 
                   nav += '<li>总页数:<i>' + totalPage + '</i></li>'; 
                   nav += '<li>当前页:<b>' + currentPage + '</b></li>'; 
                   if(currentPage == 1){ 
                       nav += '<li><a href="javascript:void(0);" title="首页">首页</a></li>'; 
                       nav += '<li><a href="javascript:void(0);" title="前一页">前一页</a></li>'; 
                   } else {                     
                       nav += '<li><a href="javascript:' + func + '(1);" title="首页">首页</a></li>'; 
                       nav += '<li><a href="javascript:' + func + '('+ (currentPage -1) +');" title="前一页">前一页</a></li>'; 
                   } 
                   nav += '<li><ol>'; 
                         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><a title="转到第1页" href="javascript:' + func + '(' + i + ');">' + i + '</a></li>'; 
                             } else {                                 
                                 nav += '<li><a title="转到第1页" href="javascript:' + func + '(' + i + ');">' + i + '</a></li>'; 
                             } 
                         } 
                          
                         nav += '</ol></li>'; 
                         if(currentPage == totalPage){ 
                             nav += '<li><a href="javascript:void(0);" title="后一页">后一页</a></li>'; 
                             nav +='<li><a href="javascript:void(0);" title="尾页">尾页</a></i>'; 
                         } else { 
                             nav += '<li><a href="javascript:' + func + '('+ (currentPage + 1) +');" title="后一页">后一页</a></li>'; 
                             nav +='<li><a href="javascript:' + func + '(' + totalPage + ');" title="尾页">尾页</a></i>'; 
                         } 
                         nav += '</ul>';     
            $("#" + divId).html(nav);            
        }; 
       this.Page = Page; 
})();

css部分:

复制代码 代码如下:

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/wgfppd.html