对象|分页|解决在论坛上有不少的关于asp分页的文章,基本思想是一致的,我把这些网友的思路深化了一下,用javaScript套上了一层基于对象的外衣,这样调用起来就不显得乱了,其它的话就不多说了,详见程序中的注释。
下边是源程序:
<script language=javascript runat=server>
function trim(str)//去掉字符串的首尾空格
{ var tmpStr=new String(str)
return tmpStr.replace(/(^\s*)|(\s*$)/g, "");
}
</script>
<SCRIPT LANGUAGE=javascript RUNAT=Server>
// ************************************************************************
// Script Compont Object Model
// Design for Active Server Pages
//
// Copyright 2003 Version 1.0
// Made by yinShuGuang
// All Rights Reserved.
// ************************************************************************
function JPageNavbar(){
_LB__Prototype();
}
function _LB__Prototype()
{
// public members
JPageNavbar.prototype.PageSize="0"
JPageNavbar.prototype.RecordCount="0" //总记录数
JPageNavbar.prototype.PageCount="1" //总页数
JPageNavbar.prototype.CurrentPage="1"
JPageNavbar.prototype.PnWidth="100%"
JPageNavbar.prototype.PnAlign="right"
JPageNavbar.prototype.PlWidth="100%" //表格宽度
JPageNavbar.prototype.PlAlign="right" // 表格的对齐方式
// private members
//public methods
JPageNavbar.prototype.getCurrentPage=_getCurrentPage
JPageNavbar.prototype.pnDisplay = _PN_show;
JPageNavbar.prototype.plDisplay = _PL_show;
//private methods
//scope implementation in _LB__Prototype function
function _getCurrentPage(){
var pageNo=new String() //当前显示的是第几页
//取得当前页
pageNo = Request.QueryString ("PageNo")
pageNo=fTrim(pageNo)
//如果没有选择第几页,则默认显示第一页;
if (pageNo=="") {
pageNo = 1
}
this.CurrentPage=pageNo
return pageNo
}
function _PL_show(){
var strBuilder=new String()
strBuilder=""
var p=(this.CurrentPage-(this.CurrentPage%10))/10 //计算分页显示的页数
//首组为第0族
strBuilder+="<table border=\"0\" cellpadding=\"0\" cellspacing=\"0\" "
strBuilder+=" width=\""+this.PlWidth+"\" align=\""+this.PlAlign+"\">"
strBuilder+=" <tr> "
strBuilder+=" <td valign=\"middle\" align=\"right\">分页:"
if (this.CurrentPage==1){
strBuilder+="<font face=\"webdings\" color=\"#ff0000\">9</font> "
}
else{
strBuilder+="<a href=\"?PageNo=1\" title=\"首页\"><font face=\"webdings\">9</font></a>
"
}
//上十页
if (p*10>0){
strBuilder+="<a href=\"?PageNo="+(p*10)+"\" title=上十页><font
face=\"webdings\">7</font></a> "
}
strBuilder+="<b>"
//分页列表
for(var i=p*10+1;i<=p*10+10;i++){
if (i==this.CurrentPage){
strBuilder+="<font color=\"#000000\">"+i+"</font> "
}
else{
strBuilder+="<a href=?PageNo="+i+" title=\"转到: 第"+i+"页\">"+i+"</a> "
}
if (i>=this.PageCount) break;
}
strBuilder+= "</b>"
//显示下十页
if (i<this.PageCount){
strBuilder+="<a href=\"?PageNo="+i+"\" title=\"下十页\"><font
face=\"webdings\">8</font></a> "
}
//显示尾页
if (this.CurrentPage==this.PageCount){
strBuilder+= "<font face=\"webdings\" color=\"#000000\">:</font> "
}
else{
strBuilder+= "<a href=?PageNo="+this.PageCount+" title=\"尾页\"><font
face=\"webdings\">:</font></a> "
}
strBuilder+= "</td></tr></table>"
Response.Write(strBuilder)
}
function _PN_show(){
var strBuilder=new String()
asp分页的基于对象的解决
80酷酷网 80kuku.com