The source code is as follows:
[Javascript]
$. Fn. pager = function (pagerInfo ){
Var recordCount = this. size ();
If (recordCount <= pagerInfo. pagesize) return;
Var currentPageIndex = 1, // The current surface. The default value is 1.
PageCount = Math. ceil (recordCount/pagerInfo. pagesize); // total number of pages
// Construct the html of the page
$ ('<Div> total' + this. size () + 'records, total '+ pageCount +' page, current <span> 1 </span> page </div> ')
. InsertAfter (pagerInfo. container)
. Append ($ ('<a class = "prev-page"> previous page </a>'). click (function (){
If (currentPageIndex = 1) return;
CurrentPageIndex --;
ShowRecords (currentPageIndex );
$ (This). prev ('span '). text (currentPageIndex );
}))
. Append ($ ('<a class = "prev-page" href> next page </a>'). click (function (){
If (currentPageIndex = pageCount) return;
CurrentPageIndex ++;
ShowRecords (currentPageIndex );
$ (This). prevAll ('span '). text (currentPageIndex );
}))
.Css(pagerInfo.css)
.Find('span'apps.css ({padding: 0 });
Var jRecords = this; // reserved Scope
// PageIndex starts with 1
Var showRecords = function (pageIndex ){
JRecords. hide (); // hide all records first
Var startIndex = (pageIndex-1) * pagerInfo. pagesize, // start record of the current page
EndIndex = (pageIndex * pagerInfo. pagesize)-1; // end record of the current page
JRecords. filter (': eq (' + startIndex + '),: gt (' + startIndex + ')'). show (); // display all records greater than the start record (inclusive)
JRecords. filter (': gt (' + endIndex + '). hide (); // hide all records greater than the end record to achieve paging Effect
};
ShowRecords (currentPageIndex );
};
Example:
[Javascript]
$ ('# Feedback ul li') // Data Source
. Pager ({
Pagesize: 10, // page size
Container: $ ('# feedback'), // container that contains html pages
Css: {'margin-left': '40px '} // pagination html Style
});
Author: bclz_vs