Home >Web Front-end >JS Tutorial >Paging function implemented in Javascript_javascript skills

Paging function implemented in Javascript_javascript skills

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOriginal
2016-05-16 19:19:311000browse

/**
* Paging class structure
* Parameter nTotalList: Total number of items
* Parameter nPageSize: Number of items displayed per 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 outputting
* Parameter nPageListSize: The maximum number of page numbers displayed in the page number list (drop-down box).该参数可省略,默认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.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  = "1";
    if (firstPage > 2)
      output  = "…";
  }
  for (var p = firstPage; p <= lastPage; p ) {
    output  = "    if (p == this.pageNum)
      output  = " selected="yes"";
    output  = ">"   p   "";
  }
  if (lastPage < this.totalPages) {
    if (lastPage < this.totalPages - 1)
      output  = "…";
    output  = ""   this.totalPages   "";
  }
  if (this.pageNum > this.totalPages)
    output  = "页码超出范围";
  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);
}

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