首頁  >  文章  >  web前端  >  javascript分頁程式碼實例分享(js分頁)_javascript技巧

javascript分頁程式碼實例分享(js分頁)_javascript技巧

WBOY
WBOY原創
2016-05-16 17:09:151247瀏覽

呼叫:

複製碼 代碼如下:

var html = pager("divid", index, 5, 1000, pageChange, { showGoTo: false, showFirst: false });
        }

實作:

複製程式碼 程式碼如下:

pager = function (divPager, pageIndex, pageSize, totalCount, pageChange, opt) {

     var theOpt = { 🎜 >         barTemplate: "{bar}  共{totalPage}頁{totalCount}條 {goto}", //顯示範本
      , //在totalPage>barSize時是自動否顯示第一頁連結
         showLast: true, //在totalPage>barSize時自動否顯示最後一頁連結
     GoTo: true / /如果太少是否自動隱藏GoTo
     };

     if (opt) {
       .barSize = opt.barSize;
         if (opt .barTemplate)
             theOpt.barTemplate = opt.barTemplate;
        theOpt.autoHide = false;
         if (opt.showFirst == false)
theOpt.showFirst = false;
         if (opt.showLast = false)
          showGoTo == false)
             theOpt.showGoTo = false;
if (opt.autoHideGoTo == false)
             theOpt.autoHideGoTo = false;
  . turn x; } (window.myPagerChanges || {} ));

     if (!myPagerChanges[divPager]) myPagerChanges[divPager] = pageChange;

  ; //分頁條終止頁
     var showFirst = true;
     var showLast = true;

      }
     pageIndex = parseInt(pageIndex);
     if (pageIndex      {
         pageIndex = Math.ceil(totalCount / pageSize);
     }

     if (totalCount == 0) { //如果沒有資料
        return "";
     }

     var totalPage = Math.ceil(totalCount / pageSize);
       document.getElementById(divPager).innerHTML = "";
         return "";
     }

     🎜>         endPage = this.totalPage;
theOpt.showLast = theOpt.showFirst = false;
     }
     else {
         if (pageIndex theOpt.showFirst = false;
         }
         else if (pageIndex,   startPage = totalPage - theOpt.barSize 1;
endPage = totalPage;
             theOpt.showLast = false;
         }
         else {                                          //中間的頁時
             startPage = pageIndex - Math.ceil(theOpt.barSize / 2) 1;
endPage = pageIndex Math.floor(theOpt.barSize / 2);
         }
             theOpt.showLast = theOpt.showFirst = false;
         }
     }

     function _getsLink      return "";
             gotoHtml = " ";
         }
     }
 re " {bar} ", barHtml)
                               .replace("{totalCount}",totalCount)
                               .replace("{pageIndex}", pageIndex)
                                .replace("{totalPage}",totalPage)
                                        。替換("{goto}", gotoHtml);

     document.getElementById(divPager).innerHTML = pagerHtml;
  
陳述:
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn