📄 tkl_pagelist.js
字号:
/*
title : page list bar
creator : tklmilk
date : 2004-9-29
example:
var plb = new PageListBar('plb', 343, 6, '?', 10);
document.write(plb);
*/
function PageListBar(name, pagecount, currpage, url, listlength)
{
this.name = name;
this.pagecount = pagecount; //total page num
this.currpage = currpage; //current page
this.url = url; //link
this.listlength = listlength?listlength:10; //number of page showed
if(this.pagecount <=0)
{
this.pagecount = 1;
}
if(this.currpage > this.pagecount)
{
this.currpage = this.pagecount;
}
}
PageListBar.prototype.go = function(pagenum)
{
window.location.href = '?currpage=' + pagenum + this.url;
}
PageListBar.prototype.goto = function()
{
var currpage = prompt("请输入跳转到的页号",this.currpage);
if(currpage)
{
if(currpage <= this.pagecount && currpage>=1)
{
this.go(currpage);
}
}
}
PageListBar.prototype.toString = function()
{
var str = '', pStart = pEnd = 1;
if(this.pagecount <= 1)
{
pStart = pEnd = 1;
}else{
if(this.pagecount <= this.listlength)
{
pStart = 1;
pEnd = this.pagecount;
}else{
var movestep = Math.round(this.listlength/2);
if(this.currpage > movestep)
{
pStart = this.currpage - movestep;
pEnd = this.currpage + movestep;
if(pEnd > this.pagecount)
{
pStart -= pEnd - this.pagecount;
pEnd = this.pagecount;
}
if(pEnd > this.pagecount)
{
pEnd = this.pagecount;
pStart -= (pEnd - this.pagecount);
}
}else{
pStart = 1;
pEnd = this.listlength;
}
}
}
for(var i=pStart; i<=pEnd; i++)
{
str += '<a href="javascript:' + this.name + '.go(' + i + ');void(0);">' + (i==this.currpage?('<b>' + i + '</b>'):i) + '</a> ';
}
str = '共' + this.pagecount + '页 <a href="javascript:' + this.name + '.go(1);void(0);">首页</a> <a href="javascript:' + this.name + '.go(' + ((this.currpage-1)<=1?1:(this.currpage-1)) + ');void(0);"' + (this.currpage==1?'disabled':'') + '><font face="webdings">3</font></a> ' + str + '<a href="javascript:' + this.name + '.go(' + ((this.currpage+1)>=this.pagecount?this.pagecount:(this.currpage+1)) + ');void(0);"' + (this.currpage==this.pagecount?'disabled':'') + '><font face="webdings">4</font></a> <a href="javascript:' + this.name + '.go(' + this.pagecount + ');void(0);">尾页</a> <a href="javascript:' + this.name + '.goto();void(0);">跳转</a>';
return str;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -