本文主要是介绍ByVal没事做写的JS页码跳转类,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
转自---〉大大IT__歇脚处--霍健伟
都是高人
学习下,学习js类的写法,从而映射到java类的写法,不知道自己的想法正确不?
=====
ByVal没事做写的JS页码跳转类
作者:dadait 日期:2005-10-31
几乎所有样式皆可依据对几个HTML原型属性的赋值变化而变化.提供了超级自由的属性以供设置风格代码未优化.
< span id ="viewlayer" ></ span >


< script language ="JavaScript" > ...

function Page()...{
this.size; //当前页两侧伸展页数
this.PageSize; //每页记录数

this.style; /**//* 统计信息HTML原型代码
元素对应:记录总数:"{$count}".总页数:"{$pagecount}".每页记录数:"{$pagesize}".当前页码:"{$pagenum}"
*/


this.liststyle; /**//* 页码列表HTML原型代码,规则形式,
将被分割成一个6个元素的数组.
例如为"首页|上一页|下一页|尾页|当前页码|普通页码"样子的HTML代码
以"{$pagenum}"为页码元素,处理后此位置则为页码值
如果有一项或多项为空仍需预留位置,如"首页|||尾页|当前页码|普通页码" */
this.jumpstyle; //自由跳转HTML原型代码
this.count; //总记录数
this.urlstyle; //附加页码前的链接代码及样式.以"{$page}"为页码元素,处理后此位置则为此链接页码值."{$location}"为链接文本元素
this.listurlstyle; //附加页码前的链接代码及样式(使用于页码列表).以"{$page}"为页码元素,处理后此位置则为此链接页码值."{$location}"为链接文本元素
this.locationPage = 1; //当前页码
this.jumpurl; //自由跳转的URL前缀
this.ParName = "page"; //页码的URL参数名


this.CreateMain = function()...{

if(this.style==null)...{
return("缺少页码样式");

}else...{
var temp
var pageCount

if(this.count%this.PageSize!=0)...{
pageCount = parseInt(this.count / this.PageSize) + 1;

}else...{
pageCount = parseInt(this.count / this.PageSize);
}
if(this.locationPage>pageCount) this.locationPage = pageCount;
temp = this.style;
temp = temp.replace("{$count}",this.count);
temp = temp.replace("{$pagecount}",pageCount);
temp = temp.replace("{$pagesize}",this.PageSize);
temp = temp.replace("{$pagenum}",this.locationPage);
return(temp);
}
}


this.CreateList = function()...{

if(this.liststyle==null)...{
return("缺少页码样式");

}else...{

if(this.count%this.size!=0)...{
ALLPageCount = parseInt(this.count / this.PageSize) + 1;

}else...{
ALLPageCount = parseInt(this.count / this.PageSize);
}
if(this.locationPage>ALLPageCount) this.locationPage = ALLPageCount;
var temp
var returnTemp = "";
var returnstr = "";
temp = this.liststyle;
temp = temp.split("|");
if(temp.length<6) return("页码列表样式定义错误");

if(temp[0]!=""&&this.locationPage>1)...{
returnTemp += this.urlstyle;
returnTemp = returnTemp.replace("{$page}",1);
returnTemp = returnTemp.replace("{$location}",temp[0]);
}

if(temp[1]!=""&&this.locationPage>1)...{
returnTemp += this.urlstyle;
returnTemp = returnTemp.replace("{$page}",this.locationPage - 1);
returnTemp = returnTemp.replace("{$location}",temp[1]);
}

if(temp[5]!="")...{
var start = this.locationPage - this.size;
var end = this.locationPage + this.size;
var looptemp = "";
if(start<1) start = 1;
if(end-start<this.size*2) end = start + this.size * 2;
if(end>ALLPageCount) end = ALLPageCount;

for(var i=start;i<=end;i++)...{
looptemp += this.listurlstyle;

if(i==this.locationPage&&temp[4]!="")...{
looptemp = looptemp.replace("{$location}",temp[4]);

}else...{
looptemp = looptemp.replace("{$location}",temp[5]);
}
looptemp = looptemp.replace("{$page}",i);
looptemp = looptemp.replace("{$pagenum}",i);
}
returnTemp += looptemp;
}

if(temp[2]!=""&&this.locationPage<ALLPageCount)...{
returnTemp += this.urlstyle;
returnTemp = returnTemp.replace("{$page}",this.locationPage + 1);
returnTemp = returnTemp.replace("{$location}",temp[2]);
}

if(temp[3]!=""&&this.locationPage<ALLPageCount)...{
returnTemp += this.urlstyle;
returnTemp = returnTemp.replace("{$page}",ALLPageCount);
returnTemp = returnTemp.replace("{$location}",temp[3]);
}
return(returnTemp);
}
}

this.CreateFreejump = function()...{
var temp = this.jumpstyle;
if(temp==null) return("缺少页码样式");

temp = temp.replace("{$page}",this.locationPage)
return(temp);
}

this.ChangePage = function()...{
var GotoPage = document.all.PageValue.value;
var ALLPageCount = 0;

if(GotoPage!=null&&GotoPage!="")...{
GotoPage = parseInt(GotoPage);

if(this.count%this.size!=0)...{
ALLPageCount = parseInt(this.count / this.PageSize) + 1;

}else...{
ALLPageCount = parseInt(this.count / this.PageSize);
}
if(GotoPage>0&&GotoPage<ALLPageCount) location.href=this.jumpurl + this.ParName + "=" + GotoPage;
}
}

this.GetPage = function()...{
var str = this.ParName + "=";
var gvalue = 1;

if(location.href.indexOf(str)>0)...{
gvalue = location.href.substring(location.href.indexOf(str) + str.length,location.href.length);
if(gvalue.indexOf('&')>0) gvalue = gvalue.substring(0,gvalue.indexOf('&'));
if(gvalue="/="") gvalue = 1;
}
return(parseInt(gvalue));
}
}

//使用实例
var P = new Page();
P.ParName = "page";
P.size = 5;
P.PageSize = 10;
P.count = 144532;
P.jumpurl = "msn.htm?";
P.locationPage = P.GetPage();


P.style = "共有...{$count}条记录.共分...{$pagecount}页.每页...{$pagesize}条.当前第...{$pagenum}页. ";

P.liststyle = "首页|<<|>>|末页|<font color=red><b>...{$pagenum}</b></font>|<b>...{$pagenum}</b>";
P.urlstyle = " <a href="msn.htm?page={$page}">{$location}</a> ";
P.listurlstyle = " [ <a href="msn.htm?page={$page}">{$location}</a> ] ";
P.jumpstyle = "<input type="text" size="5" value="{$page}" name="PageValue"> <input type=button value="跳转" οnclick="P.ChangePage()">";
viewlayer.innerHTML = P.CreateMain() + P.CreateList() + P.CreateFreejump();
</ script >
这篇关于ByVal没事做写的JS页码跳转类的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!