用jquery編寫的分頁外掛程式

來源:互聯網
上載者:User

標籤:

用jquery編寫的分頁外掛程式

源碼

function _pager_go(total_page) {    var page_str = $("#_pager_textbox").val();    var int_expr = /^(\+|-)?\d+$/;    if (!int_expr.test(page_str)) {        alert("請輸入整數");        return;    }    var go_page = parseInt(page_str);    if (go_page < 1 || go_page > total_page) {        alert("跳轉頁數超出範圍");        return;    }    var link_fn_name = $("#_pager_link_fn_name").val();    eval(link_fn_name + "(" + go_page + ")");}$.fn.ss_pager = function (options) {    var box = $(this);    var current_page = options.current_page;    var total_page = options.total_page;    var link_class_name = options.link_class || "pageitem";    var text_class_name = options.text_class || "";    var link_fn_name = options.link_fn || "void";    var show_pages = options.show_pages || 10;    var total_size = options.total_size;    var btn_class_name = options.btn_class || "btn";    if (current_page <= 1) {        current_page = 1;    }    if (total_size <= 0) {        $(box).html("<span style=‘color:red;‘>沒有記錄</span>");        return;    }    function __wprint(iscurrent, index, text) {        if (!iscurrent) {            return "<a class=‘" + link_class_name + "‘ href=‘javascript:" + link_fn_name + "(" + index + ")" + "‘>" + text + "</a>";        }        else {            return "<a class=‘" + text_class_name + "‘>" + text + "</a>";        }    }    var html_buf = ‘‘;    if (total_size) {        html_buf += __wprint(true, "", "共有" + total_size + "條記錄");    }    html_buf += __wprint(current_page - 1 <= 0, current_page - 1, "上一頁");    if (total_page > 1) {        //開始頁碼        var start = 2;        var end = total_page - 1;        var _t = parseInt(show_pages / 2) - 1;        html_buf += __wprint(current_page == 1, 1, 1);        if (current_page - _t > 1) {            html_buf += __wprint(true, "", "...");            start = current_page - _t;        }        for (var i = start; i < current_page; i++) {            html_buf += __wprint(current_page == i, i, i);            //console.log("前 "+i);        };        if (current_page > 1 && current_page < total_page) {            html_buf += __wprint(true, current_page, current_page);        }        if (current_page + _t < total_page - 1) {            end = current_page + _t;            //console.log("後 e "+ (current_page+_t));            //console.log("後 e "+ (total_page-1));        }        for (var i = current_page + 1; i <= end; i++) {            html_buf += __wprint(current_page == i, i, i);            //console.log("後 "+i);        };        if (current_page + _t < total_page - 1) {            html_buf += __wprint(true, "", "...");        };        html_buf += __wprint(current_page == total_page, total_page, total_page);    }    else {        html_buf += __wprint(current_page == 1, 1, 1);    }    html_buf += __wprint(current_page + 1 > total_page, current_page + 1, "下一頁");    html_buf += ("<a class=‘" + text_class_name + "‘> <input type=‘text‘ id=‘_pager_textbox‘ value=‘" + current_page + "‘ />");    html_buf += ("<input type=‘hidden‘ value=‘" + link_fn_name + "‘ id=‘_pager_link_fn_name‘ />");    html_buf += ("<input type=‘button‘ class=‘btn‘ value=‘轉到‘ id=‘_pager_button‘ onclick=‘_pager_go(" + total_page + ")‘ /> </a>");    $(box).html(html_buf);};

 

用jquery編寫的分頁外掛程式

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.