JS paging control, can be used for non-refresh paging
function PagerBar(recordcount, pagesize, pageindex, showpagecount) {
var NumberRegex = new RegExp(/^d $/);
this.PageIndex = 1; //Page index, current page
if (pageindex != null && NumberRegex.test(pageindex)) this.PageIndex = parseInt(pageindex);
this.PageSize = 10; //Page size
if (pagesize != null && NumberRegex .test(pagesize)) this.PageSize = parseInt(pagesize);
this.RecordCount = 0;
if (recordcount != null && NumberRegex.test(recordcount)) this.RecordCount = parseInt(recordcount); //Total number of records
this.PageCount = 0; //Total number of pages
var PagerBar = this;
function CalculatePageCount(_pagesize, _recordcount) {//Calculate the total number of pages
if (_pagesize != null && NumberRegex.test(_pagesize)) PagerBar.PageSize = parseInt(_pagesize);
if (_recordcount != null && NumberRegex.test(_recordcount)) PagerBar.RecordCount = parseInt(_recordcount);
else PagerBar. RecordCount = 0;
if (PagerBar.RecordCount % PagerBar.PageSize == 0) {//Calculate the total number of pages
PagerBar.PageCount = parseInt(PagerBar.RecordCount / PagerBar.PageSize);
}
else {
PagerBar.PageCount = parseInt(PagerBar.RecordCount / PagerBar.PageSize) 1;
}
}
if (this.RecordCount != 0) {//If passed in CalculatePageCount(this.PageSize, this.RecordCount);
}
this.ReplaceString = "《#PageLink》"; //Replace the text of the page number, note: There cannot be symbols in regular expressions
this.ShowPagesCount = 5; //Show page count
if (showpagecount != null && NumberRegex.test(showpagecount.toString())) this.ShowPagesCount = parseInt( showpagecount);
this.PreviouBarFormat = ""; //Show text format on the previous page
this.IsShowPreviouString = true; //Whether to display the previous page
this.NextBarFormat = ""; //Next Display text format on one page
this.IsShowNextString = true; //Whether to display the next page
this.PageBarFormat = ""; //Display text format on page connection
this.CurrentBarFormat = ""; // The text format displayed on the current page
this.IsShowPageString = true; // Whether to display the page index
this.FristBarFormat = ""; // The text format displayed on the homepage link
this.IsShowFristString = true; // Whether to display it Home page
this.LastBarFormat = ""; //Last page display text format
this.IsShowLastString = true; //Whether to display the last page
this.CurrentRecordBarFormat = "Current record {0}-{1} "; //Current record display text format
this.IsShowCurrentRecordString = true; //Whether to display the current record
this.CurrentPageBarFormat = "Current page " this.ReplaceString ", total" (this.PageCount == 0 ? 1: this.PageCount) "page"; //Current page text description text format
this.IsShowCurrentPageString = true; //Whether to display the current page text description text
this.OtherBarFormat = ""; //Others Also display text
this.IsShowOtherString = true; //Whether to display other page text
var regexp = new RegExp(this.ReplaceString, "g"); //Replace page number text regular expression
function GetFristPageString() {//Get home page text
Gets the home page text {> Else {
Return "" ";
}
}
function GetPreviouPageString() { //Get the previous page text
if (PagerBar.PreviouBarFormat != "") {
if (PagerBar.RecordCount > PagerBar.PageSize && PagerBar.PageIndex != 1) {//Previous page HTML output
return PagerBar.PreviouBarFormat.replace(regexp, PagerBar.PageIndex - 1);
}
}
if ( PagerBar.CurrentBarFormat != "" && PagerBar.PageBarFormat != "") {
var ShowPageFirest = PagerBar.PageIndex - parseInt(PagerBar.ShowPagesCount / 2 1) < 0 ? 0 : PagerBar.PageIndex - parseInt(PagerBar. ShowPagesCount / 2 1); //Calculate the actual number of pages displayed
if (PagerBar.PageCount < PagerBar.ShowPagesCount) {//When the total number is less than the number of displayed pages
ShowPageFirest = 0;
}
ShowPageFirest = PagerBar. PageCount - PagerBar.ShowPagesCount;
if (PagerBar. PageIndex == i 1) {
Pagestr = PagerBar.PageBarFormat.replace(regexp, i 1);
}
> return pagestr; && PagerBar.PageIndex != PagerBar.PageCount) {//Output the next page of HTMl
else {
return "";
}
}
else {
return "";
}
}
function GetLastPageString() {//获取尾页链接
if (PagerBar.LastBarFormat != "" && PagerBar.PageIndex != PagerBar.PageCount && PagerBar.RecordCount != 0) {
return PagerBar.LastBarFormat.replace(regexp, PagerBar.PageCount);
}
else {
return "";
}
}
function GetFrontOtherPageString() {//获取前其它页链接
if (PagerBar.OtherBarFormat != "") {
if (PagerBar.PageIndex > PagerBar.ShowPagesCount / 2 1) {
return PagerBar.OtherBarFormat.replace(regexp, PagerBar.PageIndex - PagerBar.ShowPagesCount <= 0 ? 1 : PagerBar.PageIndex - PagerBar.ShowPagesCount)
}
else {
return "";
}
}
else {
return "";
}
}
function GetAfterOtherPageString() {//获取后其它页链接
if (PagerBar.OtherBarFormat != "") {
if (PagerBar.PageIndex <= PagerBar.PageCount - PagerBar.ShowPagesCount / 2) {
return PagerBar.OtherBarFormat.replace(regexp,
PagerBar.PageIndex PagerBar.ShowPagesCount >= PagerBar.PageCount ? PagerBar.PageCount : PagerBar.PageIndex PagerBar.ShowPagesCount);
}
else {
return "";
}
}
else {
return "";
}
}
function GetCurrentRecordPageString() {//获取当前记录文本
if (PagerBar.CurrentRecordBarFormat != "") {
if (PagerBar.RecordCount == 0) {
return "";
}
else {
return PagerBar.CurrentRecordBarFormat.replace("{0}", (PagerBar.PageIndex - 1) * PagerBar.PageSize 1).replace("{1}", PagerBar.PageIndex * PagerBar.PageSize > PagerBar.RecordCount ? PagerBar.RecordCount : PagerBar.PageIndex * PagerBar.PageSize);
}
}
else return "";
}
function GetCurrentPageBarString() {//Get the current page record text
if (PagerBar.CurrentPageBarFormat != "") {
return PagerBar.CurrentPageBarFormat.replace(regexp, PagerBar.PageIndex);
}
else return "";
}
this.GetString = function (pageindex) {//Output HTML code (all modes)
if (pageindex != null && NumberRegex.test(pageindex)) {//If the page index is passed in, assign a value
this.PageIndex = parseInt(pageindex); CalculatePageCount(this.PageSize, this.RecordCount);
}
var pagestr = "";
if (this.IsShowCurrentPageString) {
pagestr = GetCurrentPageBarString();
🎜> pagestr = GetFristPageString();
🎜> if (this.IsShowPreviouString) {
pagestr = GetPreviouPageString();
if (this.IsShowOtherString) {
pagestr = GetF rontOtherPageString();
this.IsShowPageString) {
pagestr = GetPageString();
}
if (this.IsShowOtherString) {
pagestr = GetAfterOtherPageString(); } {
> return pagestr;
}
this.GetNormalString = function (pageindex) {
If (pageindex != null && NumberRegex.test(pageindex)) {//If the page index is passed in, assign a value
this.PageIndex = parseInt(pageindex);
var pagestr = "";
pagestr = GetFristPageString();
pagestr = GetPreviouPageString();
pagestr = GetPageString();
pagestr = GetNextPageString();
pagestr = GetLastPageString() ;
Assignment
this.PageIndex = parseInt(pageindex);
}
If (this.PageCount == 0) {//If the total number of pages has not been calculated, calculate the total number of pages
CalculatePageCount(this.PageSize, this.RecordCount);
}
var pagestr = "";
pagestr = GetPreviouPageString();
pagestr = GetCurrentPageBarString(); 🎜>
Usage example:
None yet
Knowledge points needed in the content
Page break "#PageLink"
Statement:The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn