• jquery 前台分页插件总结(1 前台假分页 2 后台分页)


    该分页插件只展示当前数据,如果前台分页需要把所有数据切割展示才能实现的前台分页

    使用前需要引入font-awesome  和分页插件js(在最下面)

    拷贝直接用即可实现,替换一下数据 

    1 前台分页情况(后台分页下次再分享)

    <!DOCTYPE html>
    <html lang="en">
    <head>
    <meta charset="UTF-8">
    <title>Title</title>
    <link rel="stylesheet" href="./font-awesome/css/font-awesome.min.css">
    <script src="http://cdn.static.runoob.com/libs/jquery/1.10.2/jquery.min.js"></script>
    <script src="simple.jquery.page.js"></script>
    <style>
    /**分页相关**/
    /*.simple-page-pre-wrap > .wrap-table td:first-child , .simple-page-pre-wrap > .wrap-table th:first-child {*/
    /*padding-left: 10px;*/
    /*}*/
    /*.simple-page-pre-wrap > .wrap-table td:last-child , .simple-page-pre-wrap > .wrap-table th:last-child {*/
    /*padding-right: 10px;*/
    /*}*/
    .simple-page {
    display: block;
    100%;
    min- 600px;
    text-align: right;
    line-height: 40px;
    margin-top: 10px;
    }
    .pre-page-icon {
    font-size: 20px;
    vertical-align: text-bottom;
    padding: 0 10px;
    color: #333;
    }
    .next-page-icon {
    font-size: 20px;
    vertical-align: text-bottom;
    padding: 0 10px;
    color: #333;
    }
    .tcdNumber {
    min- 20px;
    display: inline-block;
    text-align: center;
    line-height: 20px;
    padding: 0 3px;
    color: #333;
    }
    .current {
    min- 20px;
    display: inline-block;
    text-align: center;
    line-height: 20px;
    border-radius: 10px;
    background-color: #079cda;
    padding: 0 3px;
    color: #fff;
    }
    .page-input {
    display: inline-block!important;
    height: 20px!important;
    2.5em!important;
    margin: 0 5px 0 10px!important;
    text-align: center!important;
    outline: none!important;
    vertical-align: text-bottom;
    color: #131313;
    font-size: 13px;
    border: 1px solid #9d9d9d;
    }
    .page-jump-btn {
    padding: 5px;
    color: #333;
    }
    .simple-page-loading {
    display: none;
    color:#666;
    margin-right: 10px;
    }
    .simple-page-loading > i {
    margin-right: 10px;
    }
    .simple-page-pre-wrap {
    position: relative;
    }
    .no-simple-page > .simple-page-pre-wrap > .simplePagePre,
    .no-simple-page > .simple-page-pre-wrap > .simplePageNext {
    display: none !important;
    }
    .simplePagePre,.simplePageNext {
    display: inline-block;
    position: absolute;
    top: 0;
    46px;
    height: 100%;
    transition: all .3s;
    opacity: 0;
    }
    .simplePagePre:hover,.simplePageNext:hover {
    opacity: .8;
    }
    .simplePagePre::before,.simplePageNext::before {
    content: 'f104';
    font: normal normal normal 14px/1 FontAwesome;
    font-size: 60px;
    line-height: 80px;
    text-align: center;
    color:#fff;
    position: absolute;
    top: 50%;
    cursor: pointer;
    margin-top: -40px;
    100%;
    background-color: rgba(0,0,0,.3);
    }
    .simplePagePre {
    left: -20px;
    }
    .simplePageNext {
    right: -20px;
    }
    .simplePageNext:hover {

    }
    .simplePagePre::before {
    border-radius: 0 4px 4px 0;
    }
    .simplePageNext::before {
    content: 'f105';
    border-radius: 4px 0 0 4px;
    }

    </style>
    </head>
    <body>
    <ul class="all" >
    </ul>
    <div id="ruleExamine_hq" class="ys-page-container simple-page"></div>

    <script>
    var pageSize=1;
    var arr1=[{name:"张1", age:'18'},
    {name:"张2", age:'18'},
    {name:"张3", age:'18'},
    {name:"张4", age:'18'},
    {name:"张5", age:'18'},
    {name:"张6", age:'18'},
    {name:"张7", age:'18'},
    {name:"张8", age:'18'},
    {name:"张9", age:'18'},
    {name:"张10", age:'18'},
    {name:"张11", age:'18'},
    {name:"张12", age:'18'},
    {name:"张13", age:'18'},
    {name:"张14", age:'18'},

    ]; //后台得到的数据
    var html='';
    function list(k,arr) {
    var arrReal=arr.slice((k*pageSize-pageSize),k*pageSize); // 每一页展示的数据
    for(var i in arrReal){
    html+='<li>'+arrReal[i].name+'</li>'
    }
    $('.all').append(html);
    html=''
    }
    list(1,arr1);
    $('#ruleExamine_hq').createPage({
    current:1,
    pageCount:Math.ceil(arr1.length/pageSize),
    backFn:function (k) {
    $('.all').children('li').remove();
    list(k,arr1)
    },
    isJump:true
    })
    </script>
    </body>
    </html>
    //simple.jquery.page.js  插件代码
    (function($){
    var ms = {
    init:function(obj,args){
    return (function(){
    ms.fillHtml(obj,args);
    ms.bindEvent(obj,args);
    })();
    },
    //填充html
    fillHtml:function(obj,args){
    return (function(){
    obj.empty();
    if(!obj.hasClass('simple-page')){
    obj.addClass('simple-page');
    }
    if(obj.prev().hasClass('wrap-table')){
    if(!obj.prev().hasClass('simple-page-pre-wrap')){
    obj.prev().wrap('<div class="simple-page-pre-wrap"></div>');
    obj.prev().prepend('<span class="simplePagePre"></span>');
    obj.prev().append('<span class="simplePageNext"></span>');
    }
    }
    obj.append('<span id="'+ obj.attr('id') +'-pageLoading" class="simple-page-loading"><i class="fa fa-spinner fa-pulse"></i>数据加载中...</span>');
    //上一页
    if(args.current > 1){
    obj.append('<a href="javascript:;" class="prevPage"><i class="fa fa-angle-left pre-page-icon"></i></a>');
    }else{
    obj.remove('.prevPage');
    obj.append('<span class="disabled"><i class="fa fa-angle-left pre-page-icon"></i></span>');
    }
    //中间页码
    if(args.current != 1 && args.current >= 4 && args.pageCount != 4){
    obj.append('<a href="javascript:;" class="tcdNumber">'+1+'</a>');
    }
    if(args.current-2 > 2 && args.current <= args.pageCount && args.pageCount > 5){
    obj.append('<span>...</span>');
    }
    var start = args.current -2,end = args.current+2;
    if((start > 1 && args.current < 4)||args.current == 1){
    end++;
    }
    if(args.current > args.pageCount-4 && args.current >= args.pageCount){
    start--;
    }
    for (;start <= end; start++) {
    if(start <= args.pageCount && start >= 1){
    if(start != args.current){
    obj.append('<a href="javascript:;" class="tcdNumber">'+ start +'</a>');
    }else{
    obj.append('<span class="current">'+ start +'</span>');
    }
    }
    }
    if(args.current + 2 < args.pageCount - 1 && args.current >= 1 && args.pageCount > 5){
    obj.append('<span>...</span>');
    }
    if(args.current != args.pageCount && args.current < args.pageCount -2 && args.pageCount != 4){
    obj.append('<a href="javascript:;" class="tcdNumber">'+args.pageCount+'</a>');
    }
    //下一页
    if(args.current < args.pageCount){
    obj.append('<a href="javascript:;" class="nextPage"><i class="fa fa-angle-right next-page-icon"></i></a>');
    }else{
    obj.remove('.nextPage');
    obj.append('<span class="disabled"><i class="fa fa-angle-right next-page-icon"></i></span>');
    }
    obj.append('<span>共 '+ args.pageCount +' 页</span>');
    if(args.isJump){
    obj.append('<input type="text" class="page-input" /><a href="javascript:;" class="page-jump-btn">GO</a>');
    }
    })();
    },
    //绑定事件
    bindEvent:function(obj,args){
    return (function(){
    obj.off("click","a.tcdNumber").on("click","a.tcdNumber",function(){
    var current = parseInt($(this).text());
    ms.fillHtml(obj,{"current":current,"pageCount":args.pageCount,"isJump":args.isJump});
    if(typeof(args.backFn)=="function"){
    args.backFn(current);
    }
    });
    //上一页
    obj.off("click","a.prevPage").on("click","a.prevPage",function(){
    var current = parseInt(obj.children("span.current").text());
    ms.fillHtml(obj,{"current":current-1,"pageCount":args.pageCount,"isJump":args.isJump});
    if(typeof(args.backFn)=="function"){
    args.backFn(current-1);
    }
    });
    //下一页
    obj.off("click","a.nextPage").on("click","a.nextPage",function(){
    var current = parseInt(obj.children("span.current").text());
    ms.fillHtml(obj,{"current":current+1,"pageCount":args.pageCount,"isJump":args.isJump});
    if(typeof(args.backFn)=="function"){
    args.backFn(current+1);
    }
    });
    if(obj.prev().hasClass('simple-page-pre-wrap')){
    obj.prev().off("click","span.simplePagePre").on("click","span.simplePagePre",function () {
    var current = parseInt(obj.children("span.current").text());
    if(current==1) return;
    ms.fillHtml(obj,{"current":current-1,"pageCount":args.pageCount,"isJump":args.isJump});
    if(typeof(args.backFn)=="function"){
    args.backFn(current-1);
    }
    });
    obj.prev().off("click","span.simplePageNext").on("click","span.simplePageNext",function () {
    var current = parseInt(obj.children("span.current").text());
    if(current==args.pageCount) return;
    ms.fillHtml(obj,{"current":current+1,"pageCount":args.pageCount,"isJump":args.isJump});
    if(typeof(args.backFn)=="function"){
    args.backFn(current+1);
    }
    });
    }
    if(args.isJump){
    obj.off("click","a.page-jump-btn").on("click","a.page-jump-btn",function(){
    var _current = parseInt(obj.children("input.page-input").val());
    if(isNaN(_current)) return;
    var current = parseInt(obj.children("span.current").text());
    if(_current < 1) _current=1;
    else if(_current > args.pageCount) _current = args.pageCount;
    else if(_current == current) return;
    current = _current;
    ms.fillHtml(obj,{"current":current,"pageCount":args.pageCount,"isJump":args.isJump});
    if(typeof(args.backFn)=="function"){
    args.backFn(current);
    }
    });
    obj.off("keydown","input.page-input").on("keydown","input.page-input",function(event){
    if(event.keyCode == 13){
    var _current = parseInt(obj.children("input.page-input").val());
    if(isNaN(_current)) return;
    var current = parseInt(obj.children("span.current").text());
    if(_current < 1) _current=1;
    else if(_current > args.pageCount) _current = args.pageCount;
    else if(_current == current) return;
    current = _current;
    ms.fillHtml(obj,{"current":current,"pageCount":args.pageCount,"isJump":args.isJump});
    if(typeof(args.backFn)=="function"){
    args.backFn(current);
    }
    }
    });
    }
    })();
    }
    };
    $.fn.createPage = function(options){
    var args = $.extend({
    pageCount : 10,
    current : 1,
    backFn : function(){}
    },options);
    ms.init(this,args);
    }
    })(jQuery);
  • 相关阅读:
    jvm 垃圾收集算法
    jvm 判断对象死亡
    jvm 内存分配
    jvm 对象奥秘
    mysql事务测试及delete和update是使用行级锁,还是表级锁
    sql语句中where后边的哪些条件会使索引失效 -- SQL语句优化
    java nio详解
    mysql数据库优化概述详解
    java 序列化和反序列化
    java io框架详解
  • 原文地址:https://www.cnblogs.com/zou1234/p/8242969.html
Copyright © 2020-2023  润新知