JS分页控件

// JScript 文件

    /*
    分页控件(DEVIN 2011年02月16日)
    
    模版说明:
        标准中文:<span>共:{RecordCount}条 {PageSize}条/页 {CurrentPage}页/{PageCount}页</span> {List}
        标准英文:<span>Page {CurrentPage} of {PageCount} ({RecordCount} items) PageSize:{PageSize}</span> {List}
        使用说明:Global 参数  cn|en 中文|英文
    标记说明:
        {RecordCount}:总记录数,对应参数:RecordCount
        {PageSize}   :分页数,  对应参数:PageSize
        {CurrentPage}:当前页,  对应参数:CurrentPage
        {PageCount}  :总页数,无须输入,自动计算
        {List}       :分页模版,分页详细显示链接
    参数说明:
        RecordCount  :总记录数
        CurrentPage  :当前页
        PageSize     :分页数
        ControlId    :代码容器ID
        Attach       :附加参数(以 , 开头,多个以 , 分隔,字符串用''隔开)例:",2","2,'中国'"
        Template     :可按模版说明编辑模版,为空或无则使用标准模版
        Global       :语言,cn|en 中文|英文
        Callback     :脚本方法
    */
    String.prototype.format = function() {
        var args = arguments;
        return this.replace(/\{(\d+)\}/g, function(m, i) {
            return args[i];
        });
    };
    function Pagination(ag) {
        var $ = this;
        for (var o in ag)
            $[o] = ag[o];
        var en = $.Global && $.Global == 'en';
        $.Template = $.Template ? $.Template : !en ? '<span>共:{RecordCount}条 {PageSize}条/页 {CurrentPage}页/{PageCount}页</span> {List}' : '<span>Page {CurrentPage} of {PageCount} ({RecordCount} items) PageSize:{PageSize}</span> {List}';
        $.CurrentPage = parseInt($.CurrentPage);
        $.TotalPags = Math.ceil($.RecordCount / $.PageSize);
        $.RecordCount = parseInt($.RecordCount);

        if ($.TotalPags <= 10 || $.CurrentPage <= 9) {
            $.index = 1;
            $.endPage = 10 > $.TotalPags ? $.TotalPags : 10;
        }
        else {
            if ($.TotalPags - $.CurrentPage <= 1) {
                $.index = $.TotalPags - 8;
                $.endPage = $.TotalPags;
            } else {
                $.index = $.CurrentPage - 8;
                $.endPage = $.CurrentPage + 1;
            }
        }
        var s = [];
        
        if ($.CurrentPage > 1) {
            s.push('<a href="javascript:{0}(1{4});" title="{2}"><<</a> <a href="javascript:{0}({1}{4});" title="{3}"><</a> '.format($.Callback, ($.CurrentPage - 1), (en ? 'first' : '首页'), (en ? 'previous' : '上一页'), $.Attach));
        }
        for (var i = $.index; i <= $.endPage; i++) {
            s.push($.CurrentPage == i ? '<a class="current">{0}</a> '.format(i) : '<a href="javascript:{1}({0}{3});" title="{2}">{0}</a> '.format(i, $.Callback, (en ? 'page:{0}'.format(i) : '第{0}页'.format(i)), $.Attach));
        }
        if ($.TotalPags > $.CurrentPage) {
            s.push('<a href="javascript:{0}({1}{5});" title="{3}">></a> <a href="javascript:{0}({2}{5});" title="{4}">>></a> '.format($.Callback, ($.CurrentPage + 1), $.TotalPags, (en ? 'next' : '下一页'), (en ? 'end' : '末页'), $.Attach))
        }

        var html = $.Template;
        html = html.replace("{RecordCount}", $.RecordCount).replace("{PageSize}", $.PageSize).replace("{PageCount}", $.TotalPags).replace("{CurrentPage}", $.CurrentPage).replace('{List}', s.join(''));
        
        var o = document.getElementById($.ControlId);
        if (!o) return;
        o.innerHTML = html;
    }


调用的方法

function showPage(p) {
    //执行 AJAX 数据调用方法
    //并显示返回数据
    // p为当前页
    //调用分页方法
    new Pagination({
        RecordCount : countNum,
        CurrentPage : p,
        PageSize : 10,
        ControlId : "hotel-commente-page",//容器ID
        Attach : "",
        Template : "",
        Global : "cn",
        Callback : "AjaxHKmoHotel"//点击触发的函数
    });
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值