最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

javascript分頁代碼實(shí)例分享(js分頁)

 更新時(shí)間:2013年12月13日 09:13:08   作者:  
這篇文章主要介紹了javascript分頁實(shí)例,大家參考使用吧

調(diào)用:

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

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

實(shí)現(xiàn):

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

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

     var theOpt = {
         barSize: 5, //分頁條顯示的頁碼數(shù)  
         barTemplate: "{bar}  共{totalPage}頁{totalCount}條 {goto}", //顯示模板
         autoHide: true, //是否自動(dòng)隱藏
         showFirst: true, //在totalPage>barSize時(shí)是自動(dòng)否顯示第一頁鏈接
         showLast: true, //在totalPage>barSize時(shí)是自動(dòng)否顯示最后一頁鏈接
         showGoTo: true, //是否顯示GoTo
         autoHideGoTo: true //如果太少是否自動(dòng)隱藏GoTo
     };

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

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

     var startPage = 0;  //分頁條起始頁
     var endPage = 0;    //分頁條終止頁
     var showFirst = true;
     var showLast = true;

 
     if (isNaN(pageIndex)) {
         pageIndex = 1;
     }
     pageIndex = parseInt(pageIndex);
     if (pageIndex <= 0)
         pageIndex = 1;
     if (pageIndex * pageSize > totalCount) {
         pageIndex = Math.ceil(totalCount / pageSize);
     }

     if (totalCount == 0) { //如果沒數(shù)據(jù)
         document.getElementById(divPager).innerHTML = "";
         return "";
     }

     var totalPage = Math.ceil(totalCount / pageSize);
     if (theOpt.autoHide && totalCount <= pageSize) {   //自動(dòng)隱藏
         document.getElementById(divPager).innerHTML = "";
         return "";
     }

     if (totalPage <= theOpt.barSize) {
         startPage = 1;
         endPage = this.totalPage;
         theOpt.showLast = theOpt.showFirst = false;
     }
     else {
         if (pageIndex <= Math.ceil(theOpt.barSize / 2)) { //最前幾頁時(shí)
             startPage = 1;
             endPage = theOpt.barSize;
             theOpt.showFirst = false;
         }
         else if (pageIndex > (totalPage - theOpt.barSize / 2)) { //最后幾頁時(shí)
             startPage = totalPage - theOpt.barSize + 1;
             endPage = totalPage;
             theOpt.showLast = false;
         }
         else {                                          //中間的頁時(shí)
             startPage = pageIndex - Math.ceil(theOpt.barSize / 2) + 1;
             endPage = pageIndex + Math.floor(theOpt.barSize / 2);
         }
         if (totalPage <= (theOpt.barSize * 1.5)) {
             theOpt.showLast = theOpt.showFirst = false;
         }
     }

     function _getLink(index, txt) {
         if (!txt) txt = index;
         return "<a href='javascript:;' style='margin: 2px 5px;border: 1px solid #6d8cad;color: #0269BA;padding: 2px 5px;text-decoration: none;' onclick='myPagerChanges[\"" + divPager + "\"](" + index + ")'>" + txt + "</a>";
     }

     var barHtml = "";  //分頁條
     barHtml += pageIndex == 1 ? "" : _getLink(pageIndex - 1, "上一頁");
     if (theOpt.showFirst) {
         barHtml += _getLink(1) + "<span>...</span>";
     }
     for (var index = startPage; index <= endPage; index++) {

         if (index == pageIndex) {
             barHtml += "<span style='color:red;font-weight:blod; '>" + index + "</span>";
         }
         else {
             barHtml += _getLink(index);
         }
     }
     if (theOpt.showLast) {
         barHtml += "<span>...</span>" + _getLink(totalPage);
     }
     barHtml += pageIndex == totalPage ? "" : _getLink(pageIndex + 1, "下一頁");

     var gotoHtml = "";  //goto框及按鈕
     if (theOpt.showGoTo && theOpt.barTemplate.indexOf("{goto}") > 0) {
         if ((theOpt.autoHideGoTo && totalPage > 15) || theOpt.autoHideGoTo == false) {
             var txtid = divPager + "_goIndex";
             var indexVal = "document.getElementById(\"" + txtid + "\").value";
             gotoHtml += "<input type='text' onkeypress='if(event.keyCode==13){myPagerChanges[\"" + divPager + "\"](" + indexVal + ")}' id='" + txtid + "' value=" + pageIndex + " style='width:30px'>";
             gotoHtml += " <input type='button' class='page_bg' value='go' onclick='myPagerChanges[\"" + divPager + "\"](" + indexVal + ")'>";
         }
     }

     //替換模板
     var pagerHtml = theOpt.barTemplate.replace("{bar}", barHtml)
                               .replace("{totalCount}", totalCount)
                               .replace("{pageIndex}", pageIndex)
                               .replace("{totalPage}", totalPage)
                               .replace("{goto}", gotoHtml);

     document.getElementById(divPager).innerHTML = pagerHtml;
     return pagerHtml;
 };

相關(guān)文章

  • JS解決url傳值出現(xiàn)中文亂碼的另類辦法

    JS解決url傳值出現(xiàn)中文亂碼的另類辦法

    為什么用表單的方式就可以傳遞中文,而URL的方式就不行了呢?非得用URL傳值的方式才能解決問題嗎?這里我想到了動(dòng)態(tài)表單,何不用它來解決呢
    2013-04-04
  • 理解Javascript_10_對(duì)象模型

    理解Javascript_10_對(duì)象模型

    什么都不想說,一段代碼兩張圖,解釋一切。注:在此之前請閱讀前面的系列博文
    2010-10-10
  • JS實(shí)現(xiàn)視頻彈幕效果

    JS實(shí)現(xiàn)視頻彈幕效果

    這篇文章主要為大家詳細(xì)介紹了JS實(shí)現(xiàn)視頻彈幕效果,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2021-09-09
  • 詳解網(wǎng)站中圖片日常使用以及優(yōu)化手法

    詳解網(wǎng)站中圖片日常使用以及優(yōu)化手法

    一直都覺得網(wǎng)站優(yōu)化的重點(diǎn)是圖片,圖片的使用也是博大精深。本文將總結(jié)一下圖片的日常使用以及優(yōu)化手法,下面跟著小編一起來看下吧
    2017-01-01
  • JavaScript 防盜鏈的原理以及破解方法

    JavaScript 防盜鏈的原理以及破解方法

    這篇文章主要介紹了JavaScript 防盜鏈的原理以及破解方法,幫助大家更好的理解和使用JavaScript,感興趣的朋友可以了解下
    2020-12-12
  • 通過圖文詳細(xì)講解JavaScript中的字符串方法

    通過圖文詳細(xì)講解JavaScript中的字符串方法

    這篇文章主要介紹了JavaScript中字符串方法的相關(guān)資料,文中包括字符串長度、查找字符串、提取字符串、替換字符串、大小寫轉(zhuǎn)換、連接字符串、刪除空白符、提取字符以及字符串轉(zhuǎn)數(shù)組等方法,需要的朋友可以參考下
    2024-12-12
  • bootstrap laydate日期組件使用詳解

    bootstrap laydate日期組件使用詳解

    這篇文章主要為大家詳細(xì)介紹了bootstrap laydate日期組件使用,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2017-01-01
  • JavaScript字符串String和Array操作的有趣方法

    JavaScript字符串String和Array操作的有趣方法

    字符串和數(shù)組在程序編寫過程中是十分常用的類型,因此程序語言都會(huì)將String和Array作為基本類型,并提供許多字符串和數(shù)組的方法來簡化對(duì)字符串的操作
    2012-12-12
  • JavaScript使用html2canvas實(shí)現(xiàn)截取HTML并生成圖片

    JavaScript使用html2canvas實(shí)現(xiàn)截取HTML并生成圖片

    在前端開發(fā)中,有時(shí)我們需要將網(wǎng)頁的一部分或整個(gè)頁面截取并保存為圖片,這在生成報(bào)告、分享內(nèi)容或保存用戶界面狀態(tài)等場景中非常有用,本文將介紹如何使用 JavaScript 庫 html2canvas 來實(shí)現(xiàn)這一功能,并提供一個(gè)完整的示例,需要的朋友可以參考下
    2024-10-10
  • JavaScript分步實(shí)現(xiàn)一個(gè)出生日期的正則表達(dá)式

    JavaScript分步實(shí)現(xiàn)一個(gè)出生日期的正則表達(dá)式

    本文把出生日期分割成幾個(gè)部分,分步地介紹了實(shí)現(xiàn)一個(gè)出生日期校驗(yàn)的完整過程。對(duì)出生日期正則表達(dá)式感興趣的朋友參考下吧
    2018-03-03

最新評(píng)論

游戏| 遵义市| 邹平县| 出国| 阿拉善盟| 九寨沟县| 前郭尔| 沙坪坝区| 朔州市| 南京市| 双桥区| 望都县| 双鸭山市| 应城市| 光山县| 安庆市| 海淀区| 长阳| 垦利县| 手游| 中牟县| 金昌市| 保靖县| 乌拉特前旗| 茂名市| 蒲江县| 托里县| 泉州市| 贺州市| 葫芦岛市| 中阳县| 福建省| 万荣县| 城步| 汾西县| 古交市| 墨竹工卡县| 湘阴县| 饶平县| 北宁市| 耿马|