Universal Paging (jquery edition)

Source: Internet
Author: User

1. Simple definition of Style

<styletype= "Text/css">. Fanye{Color:Blue;Margin-right:15px;text-decoration:None;        }. Unuse{Color:Gray;        }    </style>


2. Prepare a div for rendering paging buttons

 <  body     >  <  h1  id  = "Result"  >   current page: [1]  </ h1     >  <  div  id  = "Pager"     >  </ div  >  </ body  >  

3. Write Paging function

(function($) {$.fn.pager=function(options) {varDefaults ={pagenum:1, PageCount:1        }; varopts = $.extend (true, defaults, options); //return This.each (function () {        return$( This). Empty (). Append (Renderpager (parseint (Opts.pagenum), parseint (Opts.pagecount), opts.btncallback)); //});    }; functionRenderpager (Pagenum, PageCount, btncallback) {var$pager = $ (' <div id= "PageA" ></div> "); $pager. Append (Renderbtn (' Home ', Pagenum, PageCount, Btncallback). Append (renderbtn (' previous page '), Pagenum, PageCount, Btncallback)); $pager. Append (Renderbtn (' Next page ', Pagenum, PageCount, Btncallback). Append (Renderbtn (' last '), Pagenum, PageCount, Btncallback)); //$pager. Append (' <span></span> ');        return$pager; }    functionrenderbtn (btn, Pagenum, PageCount, btncallback) {var$Button = $ (' <a href= "javascript:;" class= "fanye" > ' + btn + ' </a> '); varCurrentPage = 1; Switch(BTN) { CaseHome: CurrentPage= 1;  Break;  Case"Prev": CurrentPage= PageNum-1;  Break;  Case"Next Page": CurrentPage= Pagenum + 1;  Break;  CaseLast: CurrentPage=PageCount;  Break; }        if(btn = = "Home" | | btn = = "Previous Page") {Pagenum<= 1? $Button. addclass ("Unuse"): $Button. Click (function() {btncallback (currentpage,pagecount);}); }        Else{pagenum>= PageCount? $Button. addclass ("Unuse"): $Button. Click (function() {btncallback (currentpage, PageCount);}); }        return$Button; }}) (JQuery);


4. Call

<script type= "Text/javascript" language= "JavaScript" >$ (document). Ready (function () {            varCurrentPage = 1; varPageCount = 10;        Pagebtncallback (CurrentPage, PageCount);        }); varPagebtncallback =function(CurrentPage, PageCount) {$ ("#pager"). Pager ({pagenum:currentpage, Pagecount:pagecount, BTNCALLBACK:PAGEBT            Ncallback}); $("#result"). HTML ("current page: [" + CurrentPage + "]");           }; </script>

Universal Paging (jquery edition)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.