麻豆小视频在线观看_中文黄色一级片_久久久成人精品_成片免费观看视频大全_午夜精品久久久久久久99热浪潮_成人一区二区三区四区

首頁(yè) > 編程 > JavaScript > 正文

JS分頁(yè)控件 可用于無(wú)刷新分頁(yè)

2019-11-20 22:30:01
字體:
來(lái)源:轉(zhuǎn)載
供稿:網(wǎng)友

JS分頁(yè)控件,可用于無(wú)刷新分頁(yè)

復(fù)制代碼 代碼如下:

function PagerBar(recordcount, pagesize, pageindex, showpagecount) {
    var NumberRegex = new RegExp(/^/d+$/);
    this.PageIndex = 1; //頁(yè)索引,當(dāng)前頁(yè)
    if (pageindex != null && NumberRegex.test(pageindex)) this.PageIndex = parseInt(pageindex);
    this.PageSize = 10; //頁(yè)面大小
    if (pagesize != null && NumberRegex.test(pagesize)) this.PageSize = parseInt(pagesize);
    this.RecordCount = 0;
    if (recordcount != null && NumberRegex.test(recordcount)) this.RecordCount = parseInt(recordcount); //記錄總數(shù)
    this.PageCount = 0;  //頁(yè)總數(shù)
    var PagerBar = this;
    function CalculatePageCount(_pagesize, _recordcount) {//計(jì)算總頁(yè)數(shù)
        if (_pagesize != null && NumberRegex.test(_pagesize)) PagerBar.PageSize = parseInt(_pagesize);
        if (_recordcount != null && NumberRegex.test(_recordcount)) PagerBar.RecordCount = parseInt(_recordcount);
        else PagerBar.RecordCount = 0;
        if (PagerBar.RecordCount % PagerBar.PageSize == 0) {//計(jì)算總也頁(yè)數(shù)
            PagerBar.PageCount = parseInt(PagerBar.RecordCount / PagerBar.PageSize);
        }
        else {
            PagerBar.PageCount = parseInt(PagerBar.RecordCount / PagerBar.PageSize) + 1;
        }
    }
    if (this.RecordCount != 0) {//如果傳入了記錄總數(shù)則計(jì)算總頁(yè)數(shù)
        CalculatePageCount(this.PageSize, this.RecordCount);
    }
    this.ReplaceString = "《#PageLink》"; //替換頁(yè)數(shù)的文本,注:不可以有正則表達(dá)式中的符號(hào)
    this.ShowPagesCount = 5; //顯示頁(yè)數(shù)量
    if (showpagecount != null && NumberRegex.test(showpagecount.toString())) this.ShowPagesCount = parseInt(showpagecount);
    this.PreviouBarFormat = ""; //上一頁(yè)顯示文本格式
    this.IsShowPreviouString = true; //是否顯示上一頁(yè)
    this.NextBarFormat = ""; //下一頁(yè)顯示文本格式
    this.IsShowNextString = true; //是否顯示下一頁(yè)
    this.PageBarFormat = ""; //頁(yè)面連接顯示文本格式
    this.CurrentBarFormat = ""; //當(dāng)前頁(yè)顯示文本格式
    this.IsShowPageString = true; //是否顯示頁(yè)索引
    this.FristBarFormat = ""; //首頁(yè)鏈接顯示文本格式
    this.IsShowFristString = true; //是否顯示首頁(yè)
    this.LastBarFormat = ""; //尾頁(yè)顯示文本格式
    this.IsShowLastString = true; //是否顯示尾頁(yè)
    this.CurrentRecordBarFormat = "當(dāng)前記錄{0}-{1}"; //當(dāng)前記錄顯示文本格式
    this.IsShowCurrentRecordString = true; //是否顯示當(dāng)前記錄
    this.CurrentPageBarFormat = "當(dāng)前第" + this.ReplaceString + "頁(yè),共" + (this.PageCount == 0 ? 1 : this.PageCount) + "頁(yè)"; //當(dāng)前頁(yè)文字說(shuō)明文本格式
    this.IsShowCurrentPageString = true; //是否顯示當(dāng)前頁(yè)文字說(shuō)明文本
    this.OtherBarFormat = ""; //其他也顯示文本
    this.IsShowOtherString = true; //是否顯示其它頁(yè)文本
    var regexp = new RegExp(this.ReplaceString, "g"); //替換頁(yè)數(shù)文本正則表達(dá)式
    function GetFristPageString() {//獲取首頁(yè)文本
        if (PagerBar.FristBarFormat != "" && PagerBar.PageIndex != 1) {
            return PagerBar.FristBarFormat.replace(regexp, 1);
        }
        else {
            return "";
        }
    }
    function GetPreviouPageString() { //獲取上一頁(yè)文本
        if (PagerBar.PreviouBarFormat != "") {
            if (PagerBar.RecordCount > PagerBar.PageSize && PagerBar.PageIndex != 1) {//上一頁(yè)HTML輸出
                return PagerBar.PreviouBarFormat.replace(regexp, PagerBar.PageIndex - 1);
            }
            else {
                return "";
            }
        }
        else {
            return "";
        }
    }
    function GetPageString() {//獲取中間頁(yè)數(shù)鏈接
        var pagestr = "";
        if (PagerBar.CurrentBarFormat != "" && PagerBar.PageBarFormat != "") {
            var ShowPageFirest = PagerBar.PageIndex - parseInt(PagerBar.ShowPagesCount / 2 + 1) < 0 ? 0 : PagerBar.PageIndex - parseInt(PagerBar.ShowPagesCount / 2 + 1); //計(jì)算顯示頁(yè)數(shù)的其實(shí)頁(yè)數(shù)
            if (PagerBar.PageCount < PagerBar.ShowPagesCount) {//當(dāng)也總數(shù)小于顯示頁(yè)數(shù)量
                ShowPageFirest = 0;
            }
            else {
                if (PagerBar.PageIndex > (PagerBar.PageCount - parseInt(PagerBar.ShowPagesCount / 2 + 1))) {//當(dāng)頁(yè)總數(shù)在后幾頁(yè)顯示
                    ShowPageFirest = PagerBar.PageCount - PagerBar.ShowPagesCount;
                }
            }
            for (var i = ShowPageFirest; i < ShowPageFirest + PagerBar.ShowPagesCount; i++) {//循環(huán)出書(shū)頁(yè)數(shù)文本
                if (PagerBar.PageIndex == i + 1) {
                    pagestr += PagerBar.CurrentBarFormat.replace(regexp, i + 1);
                }
                else {
                    pagestr += PagerBar.PageBarFormat.replace(regexp, i + 1);
                }
                if (i >= PagerBar.PageCount - 1) {//當(dāng)?shù)竭_(dá)頁(yè)總數(shù)的時(shí)候挑出循環(huán)
                    break;
                }
            }
        }
        return pagestr;
    }
    function GetNextPageString() {//獲取下一頁(yè)鏈接
        if (PagerBar.NextBarFormat != "") {
            if (PagerBar.RecordCount > PagerBar.PageSize && PagerBar.PageIndex != PagerBar.PageCount) {//輸出下一頁(yè)HTMl
                return PagerBar.NextBarFormat.replace(regexp, PagerBar.PageIndex + 1);
            }
            else {
                return "";
            }
        }
        else {
            return "";
        }
    }
    function GetLastPageString() {//獲取尾頁(yè)鏈接
        if (PagerBar.LastBarFormat != "" && PagerBar.PageIndex != PagerBar.PageCount && PagerBar.RecordCount != 0) {
            return PagerBar.LastBarFormat.replace(regexp, PagerBar.PageCount);
        }
        else {
            return "";
        }
    }

    function GetFrontOtherPageString() {//獲取前其它頁(yè)鏈接
        if (PagerBar.OtherBarFormat != "") {
            if (PagerBar.PageIndex > PagerBar.ShowPagesCount / 2 + 1) {
                return PagerBar.OtherBarFormat.replace(regexp, PagerBar.PageIndex - PagerBar.ShowPagesCount <= 0 ? 1 : PagerBar.PageIndex - PagerBar.ShowPagesCount)
            }
            else {
                return "";
            }
        }
        else {
            return "";
        }
    }
    function GetAfterOtherPageString() {//獲取后其它頁(yè)鏈接
        if (PagerBar.OtherBarFormat != "") {
            if (PagerBar.PageIndex <= PagerBar.PageCount - PagerBar.ShowPagesCount / 2) {
                return PagerBar.OtherBarFormat.replace(regexp,
                PagerBar.PageIndex + PagerBar.ShowPagesCount >= PagerBar.PageCount ? PagerBar.PageCount : PagerBar.PageIndex + PagerBar.ShowPagesCount);
            }
            else {
                return "";
            }
        }
        else {
            return "";
        }
    }
    function GetCurrentRecordPageString() {//獲取當(dāng)前記錄文本
        if (PagerBar.CurrentRecordBarFormat != "") {
            if (PagerBar.RecordCount == 0) {
                return "";
            }
            else {
                return PagerBar.CurrentRecordBarFormat.replace("{0}", (PagerBar.PageIndex - 1) * PagerBar.PageSize + 1).replace("{1}", PagerBar.PageIndex * PagerBar.PageSize > PagerBar.RecordCount ? PagerBar.RecordCount : PagerBar.PageIndex * PagerBar.PageSize);
            }
        }
        else return "";
    }
    function GetCurrentPageBarString() {//獲取當(dāng)前頁(yè)記錄文本
        if (PagerBar.CurrentPageBarFormat != "") {
            return PagerBar.CurrentPageBarFormat.replace(regexp, PagerBar.PageIndex);
        }
        else return "";
    }
    this.GetString = function (pageindex) {//輸出HTML代碼(全部模式)
        if (pageindex != null && NumberRegex.test(pageindex)) {//如果傳入了頁(yè)索引則賦值
            this.PageIndex = parseInt(pageindex);
        }
        if (this.PageCount == 0) {//如果沒(méi)有計(jì)算過(guò)頁(yè)總數(shù),則計(jì)算頁(yè)總數(shù)
            CalculatePageCount(this.PageSize, this.RecordCount);
        }
        var pagestr = "";
        if (this.IsShowCurrentPageString) {
            pagestr = GetCurrentPageBarString();
        }
        if (this.IsShowCurrentRecordString) {
            pagestr += GetCurrentRecordPageString();
        }
        if (this.IsShowFristString) {
            pagestr += GetFristPageString();
        }
        if (this.IsShowPreviouString) {
            pagestr += GetPreviouPageString();
        }
        if (this.IsShowOtherString) {
            pagestr += GetFrontOtherPageString();
        }
        if (this.IsShowPageString) {
            pagestr += GetPageString();
        }
        if (this.IsShowOtherString) {
            pagestr += GetAfterOtherPageString();
        }
        if (this.IsShowNextString) {
            pagestr += GetNextPageString();
        }
        if (this.IsShowLastString) {
            pagestr += GetLastPageString();
        }
        return pagestr;
    }
    this.GetNormalString = function (pageindex) {
        if (pageindex != null && NumberRegex.test(pageindex)) {//如果傳入了頁(yè)索引則賦值
            this.PageIndex = parseInt(pageindex);
        }
        if (this.PageCount == 0) {//如果沒(méi)有計(jì)算過(guò)頁(yè)總數(shù),則計(jì)算頁(yè)總數(shù)
            CalculatePageCount(this.PageSize, this.RecordCount);
        }
        var pagestr = "";
        pagestr += GetFristPageString();
        pagestr += GetPreviouPageString();
        pagestr += GetPageString();
        pagestr += GetNextPageString();
        pagestr += GetLastPageString();
        return pagestr;
    }
    this.GetSimpleString = function (pageindex) {
        if (pageindex != null && NumberRegex.test(pageindex)) {//如果傳入了頁(yè)索引則賦值
            this.PageIndex = parseInt(pageindex);
        }
        if (this.PageCount == 0) {//如果沒(méi)有計(jì)算過(guò)頁(yè)總數(shù),則計(jì)算頁(yè)總數(shù)
            CalculatePageCount(this.PageSize, this.RecordCount);
        }
        var pagestr = "";
        pagestr += GetPreviouPageString();
        pagestr += GetCurrentPageBarString();
        pagestr += GetNextPageString();
        return pagestr;
    }
}

使用示例:

暫無(wú)

內(nèi)容中需要的知識(shí)點(diǎn)
分頁(yè)符《#PageLink》

發(fā)表評(píng)論 共有條評(píng)論
用戶(hù)名: 密碼:
驗(yàn)證碼: 匿名發(fā)表
主站蜘蛛池模板: av在线观| 99国产精品自拍 | 中午字幕无线码一区2020 | 99精品视频99| 91精品国产91久久久 | 久久日韩| 国产精品hd免费观看 | 国产一级爱c视频 | 久久精品高清 | 欧美精品日日鲁夜夜添 | 欧美日韩在线视频一区 | 毛片视频网站 | 久久免费视频一区 | 久久国产一二区 | 国产精品免费视频观看 | 欧美高清在线精品一区二区不卡 | 久久综合狠狠综合久久 | 欧美日韩中文字幕在线 | 色婷婷久久久久久 | av成人在线免费观看 | 31freehdxxxx欧美 | 噜噜噜在线| 成人影片在线免费观看 | 哪里可以看免费的av | 国产a级久久 | sese综合 | 欧美日韩大片在线观看 | 久久蜜臀一区二区三区av | 成人一级视频在线观看 | h视频在线观看免费 | 91精品国产免费久久 | www.guochanav.com| 国产精品久久久久久久久久iiiii | 成年免费大片黄在线观看岛国 | 在线成人免费观看www | 日本在线一区二区 | 久久经典国产视频 | 7777在线观看 | 99精品视频在线免费观看 | 精品一区二区三区免费毛片爱 | 日韩色电影 |