• 完善分页插件,增加内部成员,确定控件是否已经初始化过一次。


    //代码整理:懒人之家 www.lanrenzhijia.com
    //分页插件
    /**
    2014-08-05 ch
    2016-07-19 Modified By RenGuoQiang
    **/
    (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(args.current > 1){
    obj.append('<a href="javascript:;" class="prevPage">&lt</a>');
    }else{
    obj.remove('.prevPage');
    obj.append('<span class="disabled">&lt</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 -1,end = args.current+1;
    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">&gt</a>');
    }else{
    obj.remove('.nextPage');
    obj.append('<span class="disabled">&gt</span>');
    }
    })();
    },
    //绑定事件
    bindEvent:function(obj,args){
    return (function(){
    obj.on("click","a.tcdNumber",function(){
    var current = parseInt($(this).text());
    ms.fillHtml(obj,{"current":current,"pageCount":args.pageCount});
    if(typeof(args.backFn)=="function"){
    args.backFn(current);
    }
    });
    //上一页
    obj.on("click","a.prevPage",function(){
    var current = parseInt(obj.children("span.current").text());
    ms.fillHtml(obj,{"current":current-1,"pageCount":args.pageCount});
    if(typeof(args.backFn)=="function"){
    args.backFn(current-1);
    }
    });
    //下一页
    obj.on("click","a.nextPage",function(){
    var current = parseInt(obj.children("span.current").text());
    ms.fillHtml(obj,{"current":current+1,"pageCount":args.pageCount});
    if(typeof(args.backFn)=="function"){
    args.backFn(current+1);
    }
    });
    })();
    }
    }
    $.fn.createPage = function(options){
    var inited = false;
    var args = $.extend({
    pageCount : 10,
    current : 1,
    backFn : function(){}
    },options);
    alert(inited);
    if(!inited) {
    ms.init(this,args);
    inited = true;
    }
    }
    })(jQuery);

  • 相关阅读:
    hdfs搭建常见问题
    [转]opencv与Labview的结合(Dll调用)
    [转]opencv二值化的cv2.threshold函数
    忙在比赛前
    [转]使用charls抓包微信小程序的解决方案
    [转]Python调用C语言
    [转]基于Python实现matplotlib中动态更新图片(交互式绘图)
    [转]Python十六进制与字符串的转换
    STM32学习日记
    [转]Linux下的softlink和hardlink
  • 原文地址:https://www.cnblogs.com/rgqancy/p/5752770.html
Copyright © 2020-2023  润新知