var Page = function () { };
Page.prototype = {
    Loading: "<img src='/Content/Scripts/Datapager/loading.gif /><span>正在加载数据,请稍等...</span>",
    NoResult: "暂无相关数据!",
    Count: 10,
    Current: 1,
    Total: 0,
    Url: "",
    Dom: null,
    Container: null,
    Data: {},
    EXP: null,//扩展参数
    type: 0,
    CallBack: null,
    GetPageData: function () {
        $this = this;
        //if ($this.Dom) {
        //   $this.Data = new JSONSerializer().Serialize($this.Dom);
        //}
        
        this.Data.PageSize = this.Count;
        this.Data.PageNum = this.Current;
        this.Data.type = this.type;
        this.Data.EXP = this.EXP;
        this.Data._ = Math.random();
        $("#filter").hide();
        $("#dataArea").hide();
        $("#caption").html($this.Loading);
        $.ajax({
            url: $this.Url,
            async: false,
            cache: false,
            dataType: "json",
            data: $this.Data,
            success: function (result) {
                if (result.ReturnType) {
                    if (result.ReturnCount > 0) {
                        $("#pagers").show();
                        if ($this.CallBack) {
                            if ($this.Container) {
                                $this.Container.empty();
                            }
                            $this.CallBack(result.ReturnData);
                            // $this.Total = result.ReturnData[0].TotalItems;//原来写法
                            $this.Total = result.ReturnCount;//当前写法
                        }
                    }
                    else {
                        if ($this.Container) {
                            $this.Container.empty();
                        }
                        $("#mtitle").html("信息提示");
                        $("#msg").html(result.ReturnMsg);
                        $("#msg_btn").html("<a class=\"btn btn-warning\" style='border-radius:6px;'  data-dismiss=\"modal\">OK</a>");
                        $('#alertModel').modal('show');
                        $("#pagers").hide();
                    }
                }
                else {
                    if ($this.Container) {
                        $this.Container.empty();
                    }
                    $("#mtitle").html("信息提示");
                    $("#msg").html(result.ReturnMsg);
                    $("#msg_btn").html("<a class=\"btn btn-warning\" style='border-radius:6px;'  data-dismiss=\"modal\">OK</a>");
                    $('#alertModel').modal('show');
                    $("#pagers").hide();
                }
            },
            complete: function () {
                $this.Paged();
            }
        });
    },
    Paged: function () {
        var max = Math.ceil(this.Total / this.Count);
        $this = this;
        $("#btnSearch").unbind("click").click(function () {
            $this.Current = 1;
            $this.GetPageData();
        });
        $("#firstPage").unbind("click").click(function () {
            $this.Current = 1;
            $this.GetPageData();
        });
        $("#prePage").unbind("click").click(function () {
            if ($this.Current > 1) {
                $this.Current--;
                $this.GetPageData();
            }
        });
        $("#nextPage").unbind("click").click(function () {
            if ($this.Current < max) {
                $this.Current++;
                $this.GetPageData();
            }
        });
        $("#lastPage").unbind("click").click(function () {
            if ($this.Current < max) {
                $this.Current = max;
                $this.GetPageData();
            }
        });
        if ($this.Current == 1) {
            $("#firstPage,#prePage").addClass("disabled");
            $("#prePage").unbind("click");
            if ($this.Current == max) {
                $("#lastPage,#nextPage").addClass("disabled");
            }
            else {
                $("#lastPage,#nextPage").removeClass("disabled");
            }
        }
        else if ($this.Current == max) {
            $("#lastPage,#nextPage").addClass("disabled");
            $("#firstPage,#prePage").removeClass("disabled");
        }
        else {
            $("#lastPage,#nextPage,#firstPage,#prePage").removeClass("disabled");
        }
        $("#pages").val("当前第" + $this.Current + "页 共" + max + "页");
        $("#pages").unbind("blur").blur(function () {
            var page = parseInt($("#pages").val());
            if (page > 0 && page < max + 1) {
                $this.Current = page;
                $this.GetPageData();
            }
            else {
                $("#pages").val("当前第" + $this.Current + "页 共" + max + "页");
            }
        });
        $("#pages").unbind("focus").focus(function () {
            var page = $("#pages").val("");
        });
    },
    Pchange: function () {
        $this.Count = parseInt($("#selelct_PageCount").val());
        $this.Current = 1;
        $this.GetPageData();
    }
}
//初始化分页
$(function () {
    $("#selelct_PageCount").change(function () {
        var page = new Page();
        page.Pchange();
    });
});

分页样式HTML

  <!--start 分页-->
                        <div class="content-body" style="border: none; " id="pagers">
                            <div class="gigantic pagination" style="margin-top: 10px; float:left; width: 322px;">
                                <a class="first" data-action="first" id="firstPage"><i class="fa fa-angle-double-left" style="font-size: 25px;"></i></a>
                                <a class="previous" data-action="previous" id="prePage"><i class="fa fa-angle-left" style="font-size: 25px"></i></a>
                                <input type="text" id="pages" />
                                <a class="next" data-action="next" id="nextPage"><i class="fa fa-angle-right" style="font-size: 25px"></i></a>
                                <a class="last" data-action="last" id="lastPage"><i class="fa fa-angle-double-right" style="font-size: 25px"></i></a>
                            </div>
                            <div>
                                <select id="selelct_PageCount" style="margin-left: 330px; margin-top: 10px; height: 37px; width: 55px;" class="maoxian">
                                    <i class="fa-caret-down"></i>
                                    <option value="2">2</option>
                                    <option value="3">3</option>
                                    <option value="5">5</option>
                                    <option selected="selected" value="10">10</option>
                                    <option value="20">20</option>
                                    <option value="30">30</option>
                                    <option value="50">50</option>
                                    <option value="100">100</option>
                                    <option value="200">200</option>
                                    <option value="500">500</option>
                                </select>
                            </div>
                            <div class="clearfix"></div>
                        </div>
                        <!--end 分页-->

css文件

.pagination {
    position:absolute;
  display: inline-block;
  border:1px solid #cecece;
  width:320px;
  height:37px;
  border-radius: 3px; }
.pagination a {
  background-color:#1fb5ac;
  display: block;
  float: left;
  width: 30px;
  height: 30px;
  outline: none;
  color: #1fb5ac;
  vertical-align: middle;
  text-align: center;
  text-decoration: none;
  font-weight: bold;
  font-size: 16px;
  font-family: Times, 'Times New Roman', Georgia, Palatino;
  /* ATTN: need a better font stack */
  background-color: #1fb5ac;
  background-image: -webkit-gradient(linear, left top, left bottom, color-stop(0%, #f3f3f3), color-stop(100%, lightgrey));
  background-image: -webkit-linear-gradient(#fff, #fff);
  background-image: linear-gradient(#fff, #fff); }
  .pagination a:hover, .pagination a:focus, .pagination a:active {
    background-color: #fff;
    color: #000;
    background-image: -webkit-gradient(linear, left top, left bottom, color-stop(0%, #e4e4e4), color-stop(100%, #cecece));
    background-image: -webkit-linear-gradient(#e4e4e4, #e4e4e4);
    background-image: linear-gradient(#e4e4e4, #e4e4e4); 
    background-image: -webkit-linear-gradient(#fff, #fff);
    background-image: linear-gradient(#fff, #fff);
    cursor:pointer;
  }
  .pagination a.disabled, .pagination a.disabled:hover, .pagination a.disabled:focus, .pagination a.disabled:active {
    background-color: #fff;
   
    background-image: -webkit-linear-gradient(#fff, #fff);
    background-image: linear-gradient(#fff, #fff);
    color: #cecece;
    cursor: default; 
    background-color: #f3f3f3;
    background-image: -webkit-gradient(linear, left top, left bottom, color-stop(0%, #f3f3f3), color-stop(100%, lightgrey));
    background-image: -webkit-linear-gradient(#fff, #fff);
    background-image: linear-gradient(#fff, #fff);
    color: #a8a8a8;
    cursor:not-allowed;
  }
.pagination a:first-child {
  border: none;
  border-radius: 2px 0 0 2px; }
.pagination a:last-child {
  border: none;
  border-radius: 0 2px 2px 0; }
.pagination input {
  float: left;
  margin: 0;
  padding: 0;
  width: 125px;
  height: 20px;
  outline: none;
  border: none;
  vertical-align: middle;
  text-align: center; }
/* gigantic class for demo purposes */
.gigantic.pagination {
  margin: 30px 0; }
.gigantic.pagination a {
    z-index:1000;
  height: 35px;
  width: 35px;
  font-size: 31px;
  line-height: 31px; }
.gigantic.pagination input {
  width: 178px;
  height: 35px;
  font-size: 14px;
  line-height: 30px;
  border-left:1px solid #cecece;
  border-right:1px solid #cecece;
}
/* log element for demo purposes */
.log {
  display: none;
  background-color: #EDEDED;
  
  height: 300px;
  width: 524px;
  overflow: auto;
  margin-left: 0;
  list-style: none;
  padding: 10px; }
  .log li {
    margin-top: 0;
    margin-bottom: 5px; }
select.maoxian {
    border:1px solid #cecece;
    -webkit-appearance: none;
    -moz-appearance: none;
    -appearance: none;
    background               : url(/images/basic/down.png) 85% / 15% no-repeat #fdfdfd;
    border-radius: 3px;
    cursor:pointer;
    font-size:0.7em;
}
select.maoxian:hover {
    border:1px solid #cecece;
    -webkit-appearance: none;
    -moz-appearance: none;
    -appearance: none;
    background               : url(/images/basic/down-hover.png) 85% / 15% no-repeat #fdfdfd;
    border-radius: 3px;
    cursor:pointer;
    font-size:0.7em;
}
 
select.hetong {
    border:1px solid #cecece;
    -webkit-appearance: none;
    -moz-appearance: none;
    -appearance: none;
    background               : url(/images/basic/down.png) 93% / 7% no-repeat #fdfdfd;
    border-radius: 3px;
    cursor:pointer;
    font-size:0.7em;
}
select.hetong:hover {
    border:1px solid #cecece;
    -webkit-appearance: none;
    -moz-appearance: none;
    -appearance: none;
    background               : url(/images/basic/down-hover.png) 93% / 7% no-repeat #fdfdfd;
    border-radius: 3px;
    cursor:pointer;
    font-size:0.7em;
}

JS 自写datapage.js 通用分页的更多相关文章

  1. js事件委托篇(附js一般写法和js、jq事件委托写法)

    参考: jQuery代码优化:事件委托篇 使用该技术能让你避免对特定的每个节点添加事件监听器:相反,事件监听器被添加在他们的父元素上,事件监听器会分析从子元素上冒泡上来的事件,并找到是哪个子元素事件. ...

  2. 前端要革命?看我在js里写SQL

    在日新月异的前端领域中,前端工程师能做的事情越来越多,自从nodejs出现后,前端越来越有革了传统后端命的趋势,本文就再补一刀,详细解读如何在js代码中执行标准的SQL语句 为什么要在js里写SQL? ...

  3. 常见的JS手写函数汇总(代码注释、持续更新)

    最近在复习面试中常见的JS手写函数,顺便进行代码注释和总结,方便自己回顾也加深记,内容也会陆陆续续进行补充和改善. 一.手写深拷贝 <script> const obj1 = { name ...

  4. jQuery Validate 表单验证插件----通过name属性来关联字段来验证,改变默认的提示信息,将校验规则写到 js 代码中

    一.下载依赖包 网盘下载:https://yunpan.cn/cryvgGGAQ3DSW  访问密码 f224 二. 添加一个另外一个插件jquery.validate.messages_cn.js. ...

  5. asp.net尽量不在js里写<%%>

    asp.net尽量不在js里写<%%> eg: <script type="text/javascript"> var rootsid="&quo ...

  6. 轮播图--JS手写

    轮播图基本每个网站都会有,也有很多的JQuery插件可以用,这里是用JS代码写的. @{ Layout = null; } <!DOCTYPE html> <html> < ...

  7. 基于c#+xaml的前台采用IE的js引擎写后台

    基于c#+xaml的前台采用IE的js引擎写后台的猜想 参考上一篇文章 基于js的开发wp8界面的猜想知道可以使用 js的window.external.notify调用c# c#可以用InvokeS ...

  8. 给JS包写TypeScript用的类型申明文件

    TS (TypeScript)区别于JS (JavaScript)一个最大的不同是TS增加了类型.当一些TS代码要使用JS包的时候,最好这些JS包都有类型介绍,比如这个变量是什么类型,那个函数参数的什 ...

  9. 如何写一个Js上传图片插件。

    项目里面需要一个上传图片的插件,找了半天没有找到满意的,算了 不找了,自己写一个吧,顺便复习一下js方面的知识.完成之后效果还不错,当然还要继续优化,源码在最后. 介绍一种常见的js插件的写法 ; ( ...

随机推荐

  1. React学习及实例开发(二)——用Ant Design写一个简单页面

    本文基于React v16.4.1 初学react,有理解不对的地方,欢迎批评指正^_^ 一.引入Ant Design 1.安装antd yarn add antd 2.引入 react-app-re ...

  2. [bzoj4199][Noi2015]品酒大会_后缀自动机_后缀树_树形dp

    品酒大会 bzoj-4199 Noi-2015 题目大意:给定一个字符串,如果其两个子串的前$r$个字符相等,那么称这两个子串的开头两个位置$r$相似.如果两个位置勾兑在一起那么美味度为两个位置的乘积 ...

  3. linux otl oracle数据库连接例子

    #include <string> #include <iostream> using namespace std; #define OTL_ORA10G   //我连的是LI ...

  4. Java的条件判断

    以下内容引用自http://wiki.jikexueyuan.com/project/java/decision-making.html: 在 Java中有两种类型的条件判断语句,它们分别是: if语 ...

  5. 报错: The type ByteInputStream is not accessible due to restriction on required library

    报错: Access restriction:The type JPEGCodec is not accessible due to restriction on required library C ...

  6. kvm虚拟化学习笔记(四)之kvm虚拟机日常管理与配置

    KVM虚拟化学习笔记系列文章列表----------------------------------------kvm虚拟化学习笔记(一)之kvm虚拟化环境安装http://koumm.blog.51 ...

  7. [PythonCode]扫描局域网的alive ip地址

    内网的主机都是自己主动分配ip地址,有时候须要查看下有那些ip在使用,就写了个简单的脚本. linux和windows下都能够用,用多线程来ping1-255全部的地址,效率不高.2分钟左右. 先凑合 ...

  8. 提示:“请检查浏览器代理设置”/xx-net

    1.删除已导入的证书文件(运行certmgr.msc和certlm.msc,然后自己找到xxnet删),2.更新3.3.1(或是自己找到那行代码取消注释,楼下有人提及)3.删除data文件夹(下的ce ...

  9. Deepin-安装laravel

    首先获取到composer.phar wget https://getcomposer.org/download/1.6.3/composer.phar 下载以后移动到目标区域 sudo mv com ...

  10. vue 配置跨域访问

    主要在config->index.js中配置 proxyTable: { ‘/gameapi’: { changeOrigin: true, // target: ‘http://rap.id. ...