熱點推薦:
您现在的位置: 電腦知識網 >> 編程 >> Java編程 >> JSP教程 >> 正文

JS分頁控件 可用於無刷新分頁

2013-11-15 12:11:56  來源: JSP教程 
今天無意看到了這個分頁控件不過使用方法不是很清楚沒有研究大家可以自行研究裡面的函數寫法倒是不錯需要內容的結合  

  JS分頁控件可用於無刷新分頁

復制代碼 代碼如下:
function PagerBar(recordcount pagesize pageindex showpagecount) {
    var NumberRegex = new RegExp(/^d+$/);
    thisPageIndex = ; //頁索引當前頁
    if (pageindex != null && NumberRegextest(pageindex)) thisPageIndex = parseInt(pageindex);
    thisPageSize = ; //頁面大小
    if (pagesize != null && NumberRegextest(pagesize)) thisPageSize = parseInt(pagesize);
    thisRecordCount = ;
    if (recordcount != null && NumberRegextest(recordcount)) thisRecordCount = parseInt(recordcount); //記錄總數
    thisPageCount = ;  //頁總數
    var PagerBar = this;
    function CalculatePageCount(_pagesize _recordcount) {//計算總頁數
        if (_pagesize != null && NumberRegextest(_pagesize)) PagerBarPageSize = parseInt(_pagesize);
        if (_recordcount != null && NumberRegextest(_recordcount)) PagerBarRecordCount = parseInt(_recordcount);
        else PagerBarRecordCount = ;
        if (PagerBarRecordCount % PagerBarPageSize == ) {//計算總也頁數
            PagerBarPageCount = parseInt(PagerBarRecordCount / PagerBarPageSize);
        }
        else {
            PagerBarPageCount = parseInt(PagerBarRecordCount / PagerBarPageSize) + ;
        }
    }
    if (thisRecordCount != ) {//如果傳入了記錄總數則計算總頁數
        CalculatePageCount(thisPageSize thisRecordCount);
    }
    thisReplaceString = "《#PageLink》"; //替換頁數的文本不可以有正則表達式中的符號
    thisShowPagesCount = ; //顯示頁數量
    if (showpagecount != null && NumberRegextest(showpagecounttoString())) thisShowPagesCount = parseInt(showpagecount);
    thisPreviouBarFormat = ""; //上一頁顯示文本格式
    thisIsShowPreviouString = true; //是否顯示上一頁
    thisNextBarFormat = ""; //下一頁顯示文本格式
    thisIsShowNextString = true; //是否顯示下一頁
    thisPageBarFormat = ""; //頁面連接顯示文本格式
    thisCurrentBarFormat = ""; //當前頁顯示文本格式
    thisIsShowPageString = true; //是否顯示頁索引
    thisFristBarFormat = ""; //首頁鏈接顯示文本格式
    thisIsShowFristString = true; //是否顯示首頁
    thisLastBarFormat = ""; //尾頁顯示文本格式
    thisIsShowLastString = true; //是否顯示尾頁
    thisCurrentRecordBarFormat = "當前記錄{}{}"; //當前記錄顯示文本格式
    thisIsShowCurrentRecordString = true; //是否顯示當前記錄
    thisCurrentPageBarFormat = "當前第" + thisReplaceString + "頁共" + (thisPageCount == ? : thisPageCount) + "頁"; //當前頁文字說明文本格式
    thisIsShowCurrentPageString = true; //是否顯示當前頁文字說明文本
    thisOtherBarFormat = ""; //其他也顯示文本
    thisIsShowOtherString = true; //是否顯示其它頁文本
    var regexp = new RegExp(thisReplaceString "g"); //替換頁數文本正則表達式
    function GetFristPageString() {//獲取首頁文本
        if (PagerBarFristBarFormat != "" && PagerBarPageIndex != ) {
            return PagerBarFristBarFormatreplace(regexp );
        }
        else {
            return "";
        }
    }
    function GetPreviouPageString() { //獲取上一頁文本
        if (PagerBarPreviouBarFormat != "") {
            if (PagerBarRecordCount > PagerBarPageSize && PagerBarPageIndex != ) {//上一頁HTML輸出
                return PagerBarPreviouBarFormatreplace(regexp PagerBarPageIndex );
            }
            else {
                return "";
            }
        }
        else {
            return "";
        }
    }
    function GetPageString() {//獲取中間頁數鏈接
        var pagestr = "";
        if (PagerBarCurrentBarFormat != "" && PagerBarPageBarFormat != "") {
            var ShowPageFirest = PagerBarPageIndex parseInt(PagerBarShowPagesCount / + ) < ? : PagerBarPageIndex parseInt(PagerBarShowPagesCount / + ); //計算顯示頁數的其實頁數
            if (PagerBarPageCount < PagerBarShowPagesCount) {//當也總數小於顯示頁數量
                ShowPageFirest = ;
            }
            else {
                if (PagerBarPageIndex > (PagerBarPageCount parseInt(PagerBarShowPagesCount / + ))) {//當頁總數在後幾頁顯示
                    ShowPageFirest = PagerBarPageCount PagerBarShowPagesCount;
                }
            }
            for (var i = ShowPageFirest; i < ShowPageFirest + PagerBarShowPagesCount; i++) {//循環出書頁數文本
                if (PagerBarPageIndex == i + ) {
                    pagestr += PagerBarCurrentBarFormatreplace(regexp i + );
                }
                else {
                    pagestr += PagerBarPageBarFormatreplace(regexp i + );
                }
                if (i >= PagerBarPageCount ) {//當到達頁總數的時候挑出循環
                    break;
                }
            }
        }
        return pagestr;
    }
    function GetNextPageString() {//獲取下一頁鏈接
        if (PagerBarNextBarFormat != "") {
            if (PagerBarRecordCount > PagerBarPageSize && PagerBarPageIndex != PagerBarPageCount) {//輸出下一頁HTMl
                return PagerBarNextBarFormatreplace(regexp PagerBarPageIndex + );
            }
            else {
                return "";
            }
        }
        else {
            return "";
        }
    }
    function GetLastPageString() {//獲取尾頁鏈接
        if (PagerBarLastBarFormat != "" && PagerBarPageIndex != PagerBarPageCount && PagerBarRecordCount != ) {
            return PagerBarLastBarFormatreplace(regexp PagerBarPageCount);
        }
        else {
            return "";
        }
    }

    function GetFrontOtherPageString() {//獲取前其它頁鏈接
        if (PagerBarOtherBarFormat != "") {
            if (PagerBarPageIndex > PagerBarShowPagesCount / + ) {
                return PagerBarOtherBarFormatreplace(regexp PagerBarPageIndex PagerBarShowPagesCount <= ? : PagerBarPageIndex PagerBarShowPagesCount)
            }
            else {
                return "";
            }
        }
        else {
            return "";
        }
    }
    function GetAfterOtherPageString() {//獲取後其它頁鏈接
        if (PagerBarOtherBarFormat != "") {
            if (PagerBarPageIndex <= PagerBarPageCount PagerBarShowPagesCount / ) {
                return PagerBarOtherBarFormatreplace(regexp
                PagerBarPageIndex + PagerBarShowPagesCount >= PagerBarPageCount ? PagerBarPageCount : PagerBarPageIndex + PagerBarShowPagesCount);
            }
            else {
                return "";
            }
        }
        else {
            return "";
        }
    }
    function GetCurrentRecordPageString() {//獲取當前記錄文本
        if (PagerBarCurrentRecordBarFormat != "") {
            if (PagerBarRecordCount == ) {
                return "";
            }
            else {
                return PagerBarCurrentRecordBarFormatreplace("{}" (PagerBarPageIndex ) * PagerBarPageSize + )replace("{}" PagerBarPageIndex * PagerBarPageSize > PagerBarRecordCount ? PagerBarRecordCount : PagerBarPageIndex * PagerBarPageSize);
            }
        }
        else return "";
    }
    function GetCurrentPageBarString() {//獲取當前頁記錄文本
        if (PagerBarCurrentPageBarFormat != "") {
            return PagerBarCurrentPageBarFormatreplace(regexp PagerBarPageIndex);
        }
        else return "";
    }
    thisGetString = function (pageindex) {//輸出HTML代碼(全部模式)
        if (pageindex != null && NumberRegextest(pageindex)) {//如果傳入了頁索引則賦值
            thisPageIndex = parseInt(pageindex);
        }
        if (thisPageCount == ) {//如果沒有計算過頁總數則計算頁總數
            CalculatePageCount(thisPageSize thisRecordCount);
        }
        var pagestr = "";
        if (thisIsShowCurrentPageString) {
            pagestr = GetCurrentPageBarString();
        }
        if (thisIsShowCurrentRecordString) {
            pagestr += GetCurrentRecordPageString();
        }
        if (thisIsShowFristString) {
            pagestr += GetFristPageString();
        }
        if (thisIsShowPreviouString) {
            pagestr += GetPreviouPageString();
        }
        if (thisIsShowOtherString) {
            pagestr += GetFrontOtherPageString();
        }
        if (thisIsShowPageString) {
            pagestr += GetPageString();
        }
        if (thisIsShowOtherString) {
            pagestr += GetAfterOtherPageString();
        }
        if (thisIsShowNextString) {
            pagestr += GetNextPageString();
        }
        if (thisIsShowLastString) {
            pagestr += GetLastPageString();
        }
        return pagestr;
    }
    thisGetNormalString = function (pageindex) {
        if (pageindex != null && NumberRegextest(pageindex)) {//如果傳入了頁索引則賦值
            thisPageIndex = parseInt(pageindex);
        }
        if (thisPageCount == ) {//如果沒有計算過頁總數則計算頁總數
            CalculatePageCount(thisPageSize thisRecordCount);
        }
        var pagestr = "";
        pagestr += GetFristPageString();
        pagestr += GetPreviouPageString();
        pagestr += GetPageString();
        pagestr += GetNextPageString();
        pagestr += GetLastPageString();
        return pagestr;
    }
    thisGetSimpleString = function (pageindex) {
        if (pageindex != null && NumberRegextest(pageindex)) {//如果傳入了頁索引則賦值
            thisPageIndex = parseInt(pageindex);
        }
        if (thisPageCount == ) {//如果沒有計算過頁總數則計算頁總數
            CalculatePageCount(thisPageSize thisRecordCount);
        }
        var pagestr = "";
        pagestr += GetPreviouPageString();
        pagestr += GetCurrentPageBarString();
        pagestr += GetNextPageString();
        return pagestr;
    }
}

  使用示例

  暫無

  內容中需要的知識點
分頁符《#PageLink》


From:http://tw.wingwit.com/Article/program/Java/JSP/201311/20480.html
    推薦文章
    Copyright © 2005-2013 電腦知識網 Computer Knowledge   All rights reserved.