Copy Code code as follows:
/**
* Ajax Paging function
* Add <ul class= "pagination" where paging is required ></ol>
* As a paging component container element.
* PageCount Total Pages
* CurrentPage Current Page
* Container an OL container element with pagination class
* LoadData functions for loading data
* Version 1.0
*/
Pagination:function (PageCount, CurrentPage, container, LoadData) {
This.startpage = 1;
This.endpage = PageCount;
This.mindisplaypagecount = 5;
var c = $ (container);
var paginationlinks = "";
if (PageCount = = 1) {
C.css ({' Visibility ': ' Hidden '});
Return
}
if (PageCount > this.mindisplaypagecount + 1) {
if (Currentpage-this.mindisplaypagecount > 0) {
This.startpage = Currentpage-this.mindisplaypagecount;
}
if ((CurrentPage + this.mindisplaypagecount-1) < PageCount) {
This.endpage = CurrentPage + this.mindisplaypagecount-1;
} else {
This.endpage = PageCount;
}
}
Paginationlinks = "<ul>";
if (currentpage!= 1) {
Paginationlinks + + <li><a id= ' prevpage ' href= ' javascript:; ' rel= ' prev ' > Prev </a></li> ';
}
for (var i = this.startpage i <= this.endpage; i++) {
if (currentpage = = i) {
Paginationlinks + = "<li id= ' Page_" + currentpage + "_container ' ><a id= ' Page_" + i + "' class= ' current ' href= ' Java Script:; ' > "+ currentpage + </a></li>";
} else {
Paginationlinks + + "<li id= ' Page_" + i + "_container ' ><a id= ' Page_" + i + "' href= ' javascript:; ' > "+ i +" </a></li> ";
}
}
if (CurrentPage < PageCount) {
Paginationlinks + + <li><a id= ' nextpage ' href= ' javascript:; ' rel= ' Next ' > Next ' </a></li> ';
}
Paginationlinks = "</ul>";
C.html (paginationlinks);
var links = $ ("#page_number ul li a");
Links.each (function (index) {
if (!) ( this.innerhtml = "Prev" | | this.innerhtml = "Next page") {
$ (this). Click (Function (event) {
alert (links[index].innerhtml);
LoadData (Curtaskid, "", "", parseint (links[index].innerhtml));
Pagination (PageCount, parseint (links[index].innerhtml), container, loaddata);
});
}
});
var prevpage = $ ("#prevpage");
var nextPage = $ ("#nextpage");
C.css ({' Visibility ': ' Visible '});
if (prevpage) {
Prevpage.click (function (event) {
LoadData (Curtaskid, "", "", currentPage-1);
Pagination (PageCount, currentPage-1, container, loaddata);
});
}
if (nextPage) {
Nextpage.click (function (event) {
LoadData (Curtaskid, "", "", CurrentPage + 1);
Pagination (PageCount, currentpage + 1, container, loaddata);
});
}
}
LoadData is the function that loads the data, this function needs to define a parameter for the current page number, such as:
Copy Code code as follows:
var currentpage = 1;
Loadexamlist (currentpage) {
Todo
Pagination (5,currentpage,$ (UL), loadexamlist);
};
5 is the total number of pages, 1 is the current page, $ (UL) is to place the page numbers button, Loadexamlist is clicked on the previous page, next page or page number when the function called.