博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
jQuery分页插件
阅读量:7072 次
发布时间:2019-06-28

本文共 4285 字,大约阅读时间需要 14 分钟。

/** * jQuery分页插件 */+function($){    $.fn.pagination = function(options){        // 配置参数        var defaults = {            totalCount: 100, // 总条数            showPage: 5, // 显示的页数            currentPage: 1, // 当前页            perPage: 10, // 每页显示条数            callback: function (currentPage, perPage) { // 回调函数                console.log(currentPage + ':' + perPage);            }        };        $.extend(defaults, options || {});        var totalCount = parseInt(defaults.totalCount),            showPage = parseInt(defaults.showPage),            perPage = parseInt(defaults.perPage),            totalPage = Math.ceil(totalCount / perPage),            currentPage = parseInt(defaults.currentPage),            centerSep = Math.ceil(showPage / 2),            html = '';        // html结构初始化        showPage = showPage < totalPage ? showPage : totalPage;        html += '
'; $(this).html(html); var $pagination = $(this).find('.pagination'), $prev = $pagination.find('.pagination-prev'), $next = $pagination.find('.pagination-next'), $num = $pagination.find('.pagination-num'); setCurrentPage(); // 事件绑定 $pagination .delegate('.pagination-num', 'click', function(e) { currentPage = parseInt($(this).html()); setCurrentPage(); }) .delegate('.pagination-prev', 'click', function(e) { currentPage--; setCurrentPage(); }) .delegate('.pagination-next', 'click', function(e) { currentPage++; setCurrentPage(); }); // 根据当前页渲染分页 function setCurrentPage(){ currentPage = currentPage > totalPage ? totalPage : currentPage; currentPage = currentPage < 1 ? 1 : currentPage; if(currentPage == 1){ $prev.addClass('pagination-disabled'); }else{ $prev.removeClass('pagination-disabled'); } if(currentPage == totalPage){ $next.addClass('pagination-disabled'); }else{ $next.removeClass('pagination-disabled'); } if(currentPage - centerSep <= 0){ $prev.next().addClass('pagination-hidden'); }else{ $prev.next().removeClass('pagination-hidden'); } if(currentPage + centerSep > totalPage){ $next.prev().addClass('pagination-hidden'); }else{ $next.prev().removeClass('pagination-hidden'); } $num.removeClass('pagination-active').each(function (index, el) { if(currentPage - centerSep < 0){ index += 1; }else if(currentPage + centerSep > totalPage) { index = totalPage - showPage + index + 1; }else { index = currentPage - centerSep + index + 1; } if(index == currentPage){ $(el).addClass('pagination-active'); } $(el).html(index); }); $.isFunction(defaults.callback) && defaults.callback(currentPage, perPage); } }}(jQuery);
* {
margin: 0; padding: 0;}.pagination {
text-align: center;}.pagination a {
display: inline-block; padding: 5px 15px; margin-left: -1px; color: #428bca; text-decoration: none; background-color: #fff; border: 1px solid #ddd;}.pagination a:hover {
color: #2a6496; background-color: #eee; border-color: #ddd;}.pagination .pagination-disabled,.pagination .pagination-disabled:hover {
color: #777; cursor: default; background-color: #fff; border-color: #ddd;}.pagination .pagination-active,.pagination .pagination-active:hover {
color: #fff; cursor: default; background-color: #428bca; border-color: #428bca;}.pagination .pagination-hidden {
display: none;}

 

转载于:https://www.cnblogs.com/tyxloveyfq/p/4421038.html

你可能感兴趣的文章
数据库相关
查看>>
转:推荐一个包:Hashids,用来把整数生成唯一字符串(比如:通过加密解密id来隐藏真实id)...
查看>>
参考学习
查看>>
Cocos暂停和重新开始游戏
查看>>
知识发现过程
查看>>
mysql分组取每组大的记录
查看>>
Windows Server 2012 R2怎么配置域控制器?(转)
查看>>
matlab global
查看>>
php构造函数和析构函数
查看>>
javascript 坑
查看>>
Java并发常见问题
查看>>
LeetCode OJ - Valid Palindrome
查看>>
实现Windows程序的数据绑定
查看>>
离线数据存储
查看>>
bzoj 1030-1039
查看>>
[Unix学习笔记]terminal与shell之间的关系
查看>>
Dapper扩展SQL跟踪及全局缓存通知-日志入队列
查看>>
Go语言中Loop的注意点
查看>>
Ferris教程学习笔记:js示例2.15 提示框效果
查看>>
Python元组常用的操作
查看>>