一款基於jQuery的分頁外掛程式

來源:互聯網
上載者:User

標籤:com   key   var   parse   click   type   驗證   button   input   

特別提示:本人部落格部分有參考網路其他部落格,但均是本人親手編寫過並驗證通過。如發現部落格有錯誤,請及時提出以免誤導其他人,謝謝!歡迎轉載,但記得標明文章出處:http://www.cnblogs.com/mao2080/1、效果樣本

2、代碼樣式
/** 基於jquery 分頁外掛程式* by [email protected]*/$(function (){    window.pageUtil = {        /**         * 構建分頁         * @param {Object} divId 要綁定的容器         * @param {Object} data 查詢資料         * @param {Object} args 參數資訊         */        page : function(divId, data, args){            var pager = $(divId);            var pageInfo = (!data || !data.data)?{"currPage":0,"pageSize":10,"pageTotal":0,"recordTotal":0,"prevPage":0,"nextPage":0,"firstPage":0,"lastPage":0}:data.data;            pageInfo.pageTotal = this.getPageTotal(pageInfo);            var html = "<table><tbody><tr>";            if(!args.hidePageSelect){                html+=‘<td>顯示行數</td>‘;                html+=‘<td>‘;                if(!args.pageSelect){                    html+=this.getPageSelect([10, 20, 50],pageInfo.pageSize);                }else{                    html+=this.getPageSelect(args.pageSelect, pageInfo.pageSize);                }                html+=‘</td>‘;            }            html+=‘<td>共‘+pageInfo.pageTotal+‘頁,</td>‘;            html+=‘<td>轉到</td><td><input type="text" value="‘+pageInfo.currPage+‘" size="5" class="page-turn"></td>‘;            html+=‘<td>頁 第‘+this.getRowRange(pageInfo)+‘項</td>‘;            html+=‘<td>,共‘+pageInfo.recordTotal+‘項</td>‘;            html+=‘<td>‘;            if(pageInfo.currPage == 1){                html+=‘<input type="button" value="Prev" class="page-prev page-button-disable">‘;            }else{                html+=‘<input type="button" value="Prev" class="page-prev">‘;            }            if(pageInfo.currPage == pageInfo.pageTotal){                html+=‘<input type="button" value="Next" class="page-next page-button-disable">‘;            }else{                html+=‘<input type="button" value="Next" class="page-next">‘;            }            html+=‘</td>‘;            html+=‘</tr></tbody></table>‘;            pager.html(html);            pager.find(".page-select").off("change").bind("change", function(){                if(args.query){                    args.query(1, $(this).val());                }            });            pager.find(".page-turn").off("keypress").bind("keypress", function(event){                if(event.keyCode == "13" && args.query){                    var pages = $(this).val();                    if(/^\+?[1-9][0-9]*$/.test(pages) && (pages*1> 0 && pages*1 <= pageInfo.pageTotal)){                        args.query(pages, pageInfo.pageSize);                    }else{                        alert("請輸入1~"+pageInfo.pageTotal+"的數字.");                    }                }            });            pager.find(".page-prev").off("click").bind("click", function(){                if(args.query && !$(this).hasClass("page-button-disable")){                    args.query(pageInfo.currPage-1, pageInfo.pageSize);                }            });            pager.find(".page-next").off("click").bind("click", function(){                if(args.query && !$(this).hasClass("page-button-disable")){                    args.query(pageInfo.currPage+1, pageInfo.pageSize);                }            });        },        /**         * 擷取總頁數         * @param {Object} data         */        getPageTotal : function(data){            if(data.recordTotal == 0){                return 0;            }            if(data.recordTotal%data.pageSize == 0){                return data.recordTotal/data.pageSize;            }else{                return parseInt(data.recordTotal/data.pageSize)+1;            }        },        /**         * 擷取當前資料行數範圍         * @param {Object} data         */        getRowRange : function(data){            if(data.recordTotal == 0){                return "0-0";            }            if(data.currPage < data.pageTotal){                return ((data.currPage-1)*data.pageSize+1)+"-"+(data.currPage)*data.pageSize;            }else{                return ((data.currPage-1)*data.pageSize+1)+"-"+(data.recordTotal);            }        },        /**         * 構建分頁下拉框         * @param {Object} pageSelect 分頁條數         * @param {Object} pageSize 一頁大小         */        getPageSelect : function(pageSelect, pageSize){            var pageSel = ‘<select class="page-select">‘;            for(var i in pageSelect){                if(pageSelect[i] == pageSize){                    pageSel+="<option selected=‘selected‘ value="+pageSelect[i]+">"+pageSelect[i]+"</option>";                }else{                    pageSel+="<option value="+pageSelect[i]+">"+pageSelect[i]+"</option>";                }            }            return pageSel+"</select>";        }    };});

 

3、資料下載

page-demo.rar

一款基於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.