首頁  >  文章  >  web前端  >  JS分頁控制項 可用於無刷新分頁_javascript技巧

JS分頁控制項 可用於無刷新分頁_javascript技巧

WBOY
WBOY原創
2016-05-16 17:28:07992瀏覽

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

複製程式碼 程式碼如下:

function PagerBar(recordcount, pagesize, pageindex, showpagecount) {
    var NumberRegex = new RegExp(/^d $/);
  // this.PageIndex =d $/age //
    if (pageindex != null && NumberRegex.test(pageindex)) this.PageIndex = parseInt(pageindex);
    this.PageSize = 10; //頁面大小
    this.PageSize = 10; //頁面大小
page 尺寸.test(pagesize)) this.PageSize = parseInt(pagesize);
    this.RecordCount = 0;
    if (recordcount != null && NumberRegex.test(recordCountcount)) par.RecordCount. //記錄總數
    this.PageCount = 0;  //頁總數
    var PagerBar = this;
    function CalculatePageCount(_pagesize, _re>    function CalculaŠ)o(_pagesize, _reopcount>    function CalculaŠ)o(_pagesize, _reopcount>    function CalculaŠs_page(_pagesize, _reopcount) {// 計算總板數)_page        if (_recordcount != null && Number .test(_recordcount)) PagerBar.Re else PagerBar. RecordCount = 0;
        if (PagerBar.RecordCount % PagerBar.PageSize == 0) {//計算總也頁數
     🎜>        }
        else {
            PagerBar.PageCount = parseInt(PagerBar.RecordCount 🎜>    if (this.RecordCount != 0) {//如果傳入了記錄總數則計算總頁數
        CalculatePageCount(this.PageSize, this.RecordCount);
    }
    this.ReplaceString = "《#PageLink");不可以有正規表示式中的符號
    this.ShowPagesCount = 5; //顯示頁數
    if (showpagecount != null && NumberRegex.test(showpagecount.toString())) this.ShowPagesCount = parumberRegex. showpagecount);
    this.PreviouBarFormat = ""; //上一頁顯示文字格式
    this.IsShowPreviouString = true; //是否顯示上一頁
 一頁顯示文字格式
    this.IsShowNextString = true; //是否顯示下一頁
    this.PageBarFormat = ""; //頁面連結顯示文字格式
    this.Current = ""; //頁面連結顯示文字格式
    this.CurrentaBarForm目前頁顯示文字格式
    this.IsShowPageString = true; //是否顯示頁索引
    this.FristBarFormat = ""; //首頁連結顯示文字格式    this.LastBarFormat = ""; //尾頁顯示文字格式
    this.IsShowLastString = true; //是否顯示尾頁
    this.CurrentRecord "; //目前記錄顯示文字格式
    this.IsShowCurrentRecordString = true; //是否顯示目前記錄
    this.CurrentPageBarFormat = "目前第" this.ReplaceString "頁,共" (this.CurrentPageBarFormat = "目前第" this.ReplaceString "頁,共" (this.PageCount"== 0. ? 1 : this.PageCount) "頁"; //當前頁文字說明文字格式
    this.IsShowCurrentPageString = true; //是否顯示目前頁文字說明文字
    this.OtherBarFormat = ""; //也顯示文字
    this.IsShowOtherString = true; //是否顯示其它頁文字
    var regexp = new RegExp(this.ReplaceString, "g"); // 頁文字正規表示式 GetFristPageString() {//取得首頁文字
        if (PagerBar.FristBarFormat != "" && PagerBar.PageIndex != 1) {
Bar 🎜>        }
        else {
            return "";
        }
}  
    function GetPreviouPageString() { //取得上一頁文字
        if (PagerBar.PreviouBarFormat != "") {
Bar,Pager​​oagerP. agerBar.PageIndex != 1) { //上一頁HTML輸出
                                   else {
                return "";
      
        else {
            return "";
      🎜>        var pagestr = "";
        if (PagerBar .CurrentBarFormat != "" && PagerBar.PageBarFormat != "") {
            var ShowPageFirest = PagerBar.PageIndex - parseInt(Pager).SWagers Count Bar.ShowPagesCount / 2 1); //計算顯示頁數的其實頁數
            if (PagerBar.PageCount             }
            else {
                if (PagerBar.PageIndex > (PagerBar.PageCount - par/Page) 顯示總數(PageIndex > (PageIndex >PgesBar.PageCount - par)/PageCount/Pahow/Page//PaCount /PageCount - 7/PageCount/PaCount/PageCount/PaCount/PageCount/PaCount/PageCount. 🎜>                    ShowPageFirest = PagerBar.PageCount - PagerBar. ShowPagesCount;
                }
           PagesCount; i ) {//循環出書頁數文字
                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) {//當到達頁總數的時候挑出迴圈
                   }
            }
       >    }
    function GetNextPageString() {//取得下一頁連結
        if (PagerBar.NextBarFormat != "") {  ize && PagerBar.PageIndex != PagerBar .PageCount) {//輸出下一頁HTMl
                return PagerBar.NextBarFormat.replace(regexp, Pager 
            else {
               與已 "」;
            }
        }
       
        }
    }
    function GetLastPageString() {//取得尾頁連結
   . & PagerBar.RecordCount != 0 ) {
            return PagerBar.LastBarFormat.replace(regexp, PagerBar.PageCount);
        }
        else {
            return "";
        }
    }

    function GetFrontOtherPageString() {//取得前頁連結 Bar          if (PagerBar.PageIndex > PagerBar. ShowPagesCount / 2 1) {
                return PagerBar.OtherBarFormat.replace(regexp, PagerBar.PageIndex - PBar.ShowPagesCount          
          }  其他{
                返回「」;
            }
        }
       
        }
    }
    function GetAfterOtherPageString() {///取得後其他頁面連結
        if (PagerBar.PageIndex                 return PagerBar.OtherBarFormat.replace(regexp,             }
            else {
    
            }
        }
       
        }
    }
    function GetCurrentRecordPageString() {//取得目前記錄文字
         if (PagerBar.RecordCount == 0) {
                返回「」;
                    return PagerBar.CurrentRecordBarFormat.replace("{0}", (PagerBar.PageIndex - 1) * PagerBar.頁數1).replace("{ 1 }", PagerBar.PageIndex * PagerBar.PageSize > PagerBar.RecordCount : PagerBar.PageIndex * PagerBar.PageSize);
            }
        }
       否則與「"";
    }
    function GetCurrentPageBarString() {//取得目前頁面記錄文字
        if (PagerBar.CurrentPageBarFormat != " , PagerBar.PageIndex);
        }
        else return "";
    }
    this.GetString = unction (pageindex {//如果傳入了頁索引則賦值
            this.PageIndex = parseInt(pageindex);
        }
        if (this.PageCount == 0) {//如果沒有計算過頁總數,則計算頁總數
            CalculatePageCount(this.PageSize, this.RecordCount);
         if (this.IsShowCurrentPageString) {
            pagestr = GetCurrentPageBarString();
        }
        if (this.IsShowCurrentRecordString) {
      🎜>        if (this.IsShowFristString) {
            pagestr = GetFristPageString())      pagestr = GetFristPageString());
        if (this.IsShowPreviouString) {
            pagestr  .IsShowOtherString) {
            pagestr = GetFrontOtherPageString();
        }
  this.IsShowPageString) {
            pagestr = GetPageString();
             pagestr = GetAfterOtherPageString();
        }
        if (this.IsShowNextString) {
            pagestr = GetNextPageString();
        }
     pagestr = GetLastPageString();
        }
        return pagestr;
    }
this.GetNormalString = function (pageindex) {
        if (pageindex != null && NumberRegex.test(pageindex)) {//如果傳入了頁索引則賦值
🎜>        }
        if (this.PageCount == 0) {//如果沒有計算頁總數,則計算頁總數 >        }
var pagestr = "";
        pagestr = GetFristPageString();
        pagestr = GetPreviou     pagestr = GetNextPageString();
        pagestr = GetLastPageString() ;
        return pagestr;
    }
    this.GetSimpleString = function (pageindex) {             this.PageIndex = parseInt(pageindex);
        }
If (this.PageCount == 0) {//総ページ数が計算されていない場合は、総ページ数を計算します
CalculatePageCount(this.PageSize, this.RecordCount)
}
var pagestr = "";
pagestr = GetPreviouPageString();
pagestr = GetCurrentPageBarString();
使用例:

まだありません

コンテンツに必要な知識ポイント
改ページ "#PageLink"
陳述:
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn