Javascript实现的分页函数

2019-06-03 06:36:12刘景俊

      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">页码超出范围</option>";
  output += "</select>";
  output += "/" + this.totalPages + " 页 ";
  if (this.pageNum == 1) {
    output += "[首页] ";
    output += "[上页] ";
  }
  else {
    output += "<a href="" + this.pageUrl.replace(/[pn]/, "1") + "">[首页]</a> ";
    output += "<a href="" + this.pageUrl.replace(/[pn]/, this.pageNum-1) + "">[上页]</a> ";
  }
  if (this.pageNum == this.totalPages) {
    output += "[下页] ";
    output += "[尾页]";
  }
  else {
    output += "<a href="" + this.pageUrl.replace(/[pn]/, this.pageNum+1) + "">[下页]</a> ";
    output += "<a href="" + this.pageUrl.replace(/[pn]/, this.totalPages) + "">[尾页]</a> ";
  }
  output += "</td></tr></table>";
  document.writeln(output);
}