Home > Web Front-end > JS Tutorial > Paging function implemented by Javascript_JavaScript

Paging function implemented by Javascript_JavaScript

WBOY
Release: 2016-05-16 19:22:51
Original
1387 people have browsed it

From: IECN.Net ; Author: Zhongzhong

/**
* Paging class structure
* Parameter nTotalList: Total number of items
* Parameter nPageSize: Number of items displayed on each page
* Parameter nPageNum: Current page number
* Parameter sPageUrl: The URL of the paging link, the page number is replaced by [pn], which will be replaced by the actual page number when output
* Parameter nPageListSize: The page number list (drop-down box) displayed Maximum number of page numbers.该参数可省略,默认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 pagination and output HTML directly
* No parameters
* No return value
*/
Pagination.prototype.generate = function() {
  var output = "";
  output  = "

";
  output  = "共 "   this.totalList   " 条 每页 "   this.pageSize   " 条 当前第 ";
  output  = "";
  output  = "/"   this.totalPages   " 页 ";
  if (this.pageNum == 1) {
    output  = "[首页] ";
    output  = "[上页] ";
  }
  else {
    output  = "[首页] ";
    output  = "[上页] ";
  }
  if (this.pageNum == this.totalPages) {
    output  = "[下页] ";
    output  = "[尾页]";
  }
  else {
    output  = "[下页] ";
    output  = "[尾页] ";
  }
  output  = "
";
  document.writeln(output);
}
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template