📄 page.js
字号:
/**
* filename: page.js
* @package:phpbean
* @author :feifengxlq<feifengxlq#gmail.com><http://www.phpobject.net/>
* @copyright :Copyright 2006 feifengxlq
* @license:version 1.0beta
* @create:2007-1-2
* description:超强JS分页类,四种分页模式,默认采用类似baidu,google的分页风格。
* to see detail,please visit http://www.phpobject.net/blog/read.php?
* example:
function showpage(nowpage){
page.construct(1000,20,'<% =romPrefix(NULL) %>/jspage.csp&page=',nowpage);
document.write(page.show(1));
}
开启AJAX:
function ajaxpage(nowpage){
page.construct(1000,20,'ajax.php?page=',nowpage,true,'ajax_page');
document.write(page.show(1));
}
采用继承自定义分页显示模式:
function mypage(nowpage){
page.construct(1000,20,'<% =romPrefix(NULL) %>/jspage.csp&page=',nowpage);
page._next_page='>';
page._pre_page='<';
page._first_page='<<';
page._last_page='>>';
page._is_ajax=false;
document.write(page._first()+' '+page._pre()+' '+page._next()+' '+page._last());
}
*/
var page={
_pagebarnum : 10,
_totalpage : 1,
_nowpage : 1,
_pageurl : '',//eg. '/<% =romPrefix(NULL) %>/index.csp&pagename=' or '<% =romPrefix(NULL) %>/index.csp&id=1&pagename='
_is_ajax : false,
_ajax_page : '',
/**setting*/
_next_page : '>',
_pre_page : '<',
_first_page : '首页',
_last_page : '尾页',
_text_left : '[',
_text_right : ']',
_pagebarnum : 10,
/**
* 构造函数
*/
construct:function(total,perpage,pageurl,nowpage,is_ajax,ajax_page){
this._pageurl=pageurl;
if(nowpage!=null && nowpage!='')this._nowpage=parseInt(nowpage);
this._totalpage=Math.ceil(total/perpage);
if(is_ajax!=null && is_ajax!=''){
this._is_ajax=is_ajax;
this._ajax_page=ajax_page;
}
},
/**
* 获取下一页
*/
_next:function(style){
if(this._nowpage<this._totalpage){
return this._getlink(this._nowpage+1,this._next_page,this._getstyle(style));
}
return '<span'+this._getstyle(style)+'>'+this._next_page+'</span>';
},
/**
* 获取上一页
*/
_pre:function(style){
if(this._nowpage>1){
return this._getlink(this._nowpage-1,this._pre_page,this._getstyle(style));
}
return '<span'+this._getstyle(style)+'>'+this._pre_page+'</span>';
},
/**
* 获取第一页
*/
_first:function(style){
if(this._nowpage!=1){
return this._getlink(1,this._first_page,this._getstyle(style));
}
return '<span'+this._getstyle(style)+'>'+this._first_page+'</span>';
},
/**
* 获取最后一页
*/
_last:function(style){
if(this._nowpage!=this._totalpage){
return this._getlink(this._totalpage,this._last_page,this._getstyle(style));
}
return '<span'+this._getstyle(style)+'>'+this._last_page+'</span>';
},
/**
* 获取显示的分页栏,默认当前页面在最前面
* @param style 未选中的风格
* @param nowstyle 当前页面的风格
*/
_pagebar:function(style,nowstyle){
var plus=Math.ceil(this._pagebarnum/2);
if(this._pagebarnum-plus+this._nowpage>this._totalpage)plus=this._nowpage+this._pagebarnum-this._totalpage;
var begin=this._nowpage-plus+1;
if(begin<1)begin=1;
var returnstr='';
for(i=begin;i<begin+this._pagebarnum;i++){
if(i<=this._totalpage){
if(i==this._nowpage){
returnstr+=this._text_left+'<span'+this._getstyle(nowstyle)+'>'+i+'</span>'+this._text_right;
}else{
returnstr+=this._text_left+this._getlink(i,i,this._getstyle(style))+this._text_right;
}
}else{
break;
}
}
return returnstr;
},
/**
* 显示下拉列表
*/
_select:function(){
var returnstr='<select onchange="';
if(this._is_ajax){
//ajax
returnstr+=this._ajax_page+"('"+this._pageurl+"'+this.options[this.selectedIndex].value)";
}else{
returnstr+="window.location.href='"+this._pageurl+"'+this.options[this.selectedIndex].value";
}
returnstr+='">';
for(i=1;i<=this._totalpage;i++){
if(i==this._nowpage){
returnstr+='<option value="'+i+'" selected>'+i+'</option>';
}else{
returnstr+='<option value="'+i+'">'+i+'</option>';
}
}
return returnstr+'</select>';
},
/**
* 返回结果
*/
show:function(mode){
if((mode==null)||(mode==''))mode=1;
switch(mode)
{
case 1:
this._pre_page='上一页';
this._next_page='下一页';
return this._pre()+this._pagebar()+this._next()+this._select();
case 2:
this._pre_page='上一页';
this._next_page='下一页';
this._first_page='首页';
this._last_page='尾页';
return this._first()+this._pre()+'[第'+this._nowpage+'页]'+this._next()+this._last()+'第'+this._select()+'页';
case 3:
this._pre_page='上一页';
this._next_page='下一页';
return this._first()+' '+this._pre()+this._next()+' '+this._last()+this._select();
case 4:
this._pre_page='上一页';
this._next_page='下一页';
return this._first()+' '+this._pre()+this._pagebar()+this._next()+' '+this._last()+this._select();
}
},
/**private-----*/
/**
* 获取页面的链接
* @pageno 页面值。第几页
* @pagename 页面显示的文字
* @style 显示的风格
* @return 分页链接
*/
_getlink:function(pageno,pagename,style){
if((pagename==null)||(pagename==''))pagename=pageno
if(this._is_ajax){
//ajax模式
return '<a href="javascript:'+this._ajax_page+'(\''+this._pageurl+pageno+'\')"'+style+'>'+pagename+'</a>';
}else{
//一般模式
return '<a href="'+this._pageurl+pageno+'"'+style+'>'+pagename+'</a>';
}
},
/**
* 获取风格
*/
_getstyle:function(style){
if(style!=null && style!=''){
style=' class="'+style+'"';
}else{
style='';
}
return style;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -