基於jquery編寫分頁外掛程式,jquery編寫分頁外掛程式

來源:互聯網
上載者:User

基於jquery編寫分頁外掛程式,jquery編寫分頁外掛程式

擴充JQuery很容易,作為一個練習,編寫一個簡單的分頁外掛程式,代碼量不大,直接看代碼好了:

$.fn.mypagination = function(totalProperty,opts){   opts = $.extend({     perPage:10,       callback:function(){     }   },opts||{});        return this.each(function(){     function numPages(){       return Math.ceil(totalProperty/opts.perPage);     }            function selectPage(page){       return function(){         currPage = page;         if (page<0) currPage = 0;         if (page>=numPages()) currPage = numPages()-1;         render();           $('img.page-wait',panel).attr('src','images/wait.gif');         opts.callback(currPage+1);         $('img.page-wait',panel).attr('src','images/nowait.gif');       }     }          function render(){         var html = '<table><tbody><tr>'          +'<td><a href="#"><img class="page-first"></a></td>'         +'<td><a href="#"><img class="page-prev"></a></td>'         +'<td><span>第<input type="text" class="page-num">頁/共'+numPages()+'頁</span></td>'         +'<td><a href="#"><img class="page-next"></a></td>'         +'<td><a href="#"><img class="page-last"></a></td>'         +'<td><img src="images/nowait.gif" class="page-wait"></td>'         +'<td><span style="padding-left:50px;">檢索到'+totalProperty+'記錄</span></td>'         +'</tr></tbody></table>';       var imgFirst = 'images/page-first-disabled.gif';       var imgPrev = 'images/page-prev-disabled.gif';       var imgNext = 'images/page-next-disabled.gif';       var imgLast = 'images/page-last-disabled.gif';       if (currPage > 0){         imgFirst = 'images/page-first.gif';         imgPrev = 'images/page-prev.gif';       }       if (currPage < numPages()-1){         imgNext = 'images/page-next.gif';         imgLast = 'images/page-last.gif';       }       panel.empty();       panel.append(html);       $('img.page-first',panel)         .bind('click',selectPage(0))         .attr('src',imgFirst);        $('img.page-prev',panel)         .bind('click',selectPage(currPage-1))         .attr('src',imgPrev);         $('img.page-next',panel)         .bind('click',selectPage(currPage+1))         .attr('src',imgNext);         $('img.page-last',panel)         .bind('click',selectPage(numPages()-1))         .attr('src',imgLast);       $('input.page-num',panel)         .val(currPage+1)         .change(function(){           selectPage($(this).val()-1)();         });     }          var currPage = 0;     var panel = $(this);     render();     }); } 

下面測試一下:

<head>   <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />   <link rel="stylesheet" href="mypagination.css"/>   <script type="text/javascript" src="jquery-1.2.6.js"></script>   <script type="text/javascript" src="jquery.mypagination.js"></script>   <script>     $(document).ready(function(){       $('#mypage').mypagination(10112,{         callback:function(page){           alert(page);         }       });     });   </script> </head> <div id="mypage" class="mypagination"></div> 

運行如下:

以上就是本文的全部內容,希望對大家的學習有所協助。

您可能感興趣的文章:
  • 一款Jquery 分頁外掛程式的改造方法(伺服器端分頁)
  • 分享精心挑選的12款優秀jQuery Ajax分頁外掛程式和教程
  • asp.net jquery無重新整理分頁外掛程式(jquery.pagination.js)
  • jQuery Pagination Ajax分頁外掛程式(分頁切換時無重新整理與延遲)中文翻譯版
  • jquery分頁外掛程式AmSetPager(自寫)
  • jQuery外掛程式分享之分頁外掛程式jqPagination
  • 分享一個自己動手寫的jQuery分頁外掛程式
  • 基於bootstrap3和jquery的分頁外掛程式
  • Jquery 分頁外掛程式之Jquery Pagination
  • 使用JQuery實現的分頁外掛程式分享

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.