?? 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 + -