From: IECN. Net; Author: Clock
/**
* Paging Class Construction
* Parameter nTotalList: Total number of entries
* Parameter nPageSize: number of entries displayed per page
* Parameter nPageNum: Current page number
* Parameter sPageUrl: the URL of the paging link. The page number is replaced by [pn], and the actual page number is replaced when output.
* Parameter nPageListSize: Maximum number of pages displayed in the page number list (drop-down box. This parameter can be omitted. The default value is 100.
*/
Function Pagination (nTotalList, nPageSize, nPageNum, sPageUrl, nPageListSize ){
This. totalList = nTotalList;
This. pageSize = nPageSize;
This. pageNum = nPageNum;
If (nTotalList = 0)
This. totalPages = 1;
Else
This. totalPages = Math. floor (this. totalList-1)/this. pageSize + 1 );
This. pageUrl = sPageUrl;
If (arguments [4])
This. pageListSize = nPageListSize;
Else
This. pageListSize = 100;
}
/**
* Generate pages and output HTML directly.
* No Parameter
* No Return Value
*/
Pagination. prototype. generate = function (){
Var output = "";
Output ++ = "<table width = \" 98% \ "cellspacing = \" 1 \ "cellpadding = \" 3 \ "align = \" center \ "> <tr> <td align = \ "right \"> ";
Output + = "Total" + this. totalList + "entries per page" + this. pageSize + "entries current ";
Output + = "<select onchange = \" if (this. value) location. href = '"+ this. pageUrl + "'. replace (// \ [pn \]/, ";
Output + = "this. value); \" align = \ "absMiddle \" style = \ "font: normal 9px Verdana, Arial,; \"> ";
Var firstPage = this. pageNum-Math. floor (this. pageListSize/2 );
If (firstPage <1)
FirstPage = 1;
Var lastPage = firstPage + this. pageListSize-1;
If (lastPage> this. totalPages ){
LastPage = this. totalPages;
FirstPage = lastPage-this. pageListSize + 1;
If (firstPage <1)
FirstPage = 1;
}
If (firstPage> 1 ){
Output + = "<option value = \" 1 \ "> 1 </option> ";
If (firstPage> 2)
Output + = "<option value = \" \ ">... </Option> ";
}
For (var p = firstPage; p <= lastPage; p ++ ){
Output + = "<option value = \" "+ p + "\"";
If (p = this. pageNum)
Output + = "selected = \" yes \"";
Output + = ">" + p + "</option> ";
}
If (lastPage <this. totalPages ){
If (lastPage <this. totalPages-1)
Output + = "<option value = \" \ ">... </Option> ";
Output + = "<option value = \" "+ this. totalPages +" \ ">" + this. totalPages + "</option> ";
}
If (this. pageNum> this. totalPages)
Output + = "<option value = \" \ "selected = \" yes \ "> page number out of range </option> ";
Output + = "</select> ";
Output + = "/" + this. totalPages + "page ";
If (this. pageNum = 1 ){
Output + = "[homepage]";
Output + = "[Previous Page]";
}
Else {
Output + = "<a href = \" "+ this. pageUrl. replace (/\ [pn \]/, "1") + "\"> [homepage] </a> ";
Output + = "<a href = \" "+ this. pageUrl. replace (/\ [pn \]/, this. pageNum-1) + "\"> [Previous Page] </a> ";
}
If (this. pageNum = this. totalPages ){
Output + = "[Next Page]";
Output + = "[last page]";
}
Else {
Output + = "<a href = \" "+ this. pageUrl. replace (/\ [pn \]/, this. pageNum + 1) + "\"> [Next Page] </a> ";
Output + = "<a href = \" "+ this. pageUrl. replace (/\ [pn \]/, this. totalPages) + "\"> [last page] </a> ";
}
Output + = "</td> </tr> </table> ";
Document. writeln (output );
}