服务端 JScript 记录集分页函数/对象 By shawl.qiu
说明:
分页其实很简单的, 我都写了好几个分页函数了...
感觉 JScript 写代码比 VBScript 方便不少, 基本恋上用 类C 语法写代码, BASIC 语法快看不懂了....
唉, 没啥好说的, 这次用 JScript 写了两个分页程序, 一个是 Jscript 对象, 一个是Jscript 函数对象, 我比较喜欢 Jscript 对象, 不需要像函数对象那样 new obj 使用.
注: 对象需要在使用之前定义, 函数对象可在使用后定义.
广告时间:
我的 HTML 编辑器已经写好了, 取名 sqEditor, 支持 Opera, IE, Firefox.
暂不公开.
附:
vbs 记录集分页: ASP VBScript 分页函数 by Stabx, 第三版
URL: http://blog.csdn.net/btbtd/archive/2006/05/31/765595.aspx
vbs 文章分页:
ASP 通用文章分页函数(非记录集分页), 返回多个结果, 字典实现 By shawl.qiu
URL: http://blog.csdn.net/btbtd/archive/2006/09/04/1175126.aspx
目录:
1. JScript 记录集分页对象
2. JScript 记录集分页函数对象
shawl.qiu
2006-11-26
1. JScript 记录集分页对象
linenum
<%@LANGUAGE="JAVASCRIPT" CODEPAGE="65001"%>
<%
//-----------------------------begin object oPgnt-----------------------------//
var oPgnt={
//------------------------------------begin list
list:function(obj, articleInPage, pagelink, currentPage, identifier){
/*------------------------------------------------*\
* 服务端 JScript 记录集分页对象 By shawl.qiu
* ----------------------
* 参数说明:
* obj: 对象, recordset 对象;
* articleInPage: 数值, 每页分页大小;
* pagelink: 数值, 显示页面链接数;
* currentPage: 数值, 当前 request 查询的 页位置.
* identifier: 字串, 访问分页 request 识别符.
\*------------------------------------------------*/
if(!obj)return false;
if(obj.Eof||obj.Bof)return false;
if(!articleInPage)var articleInPage=10;
if(!currentPage) var currentPage=1;
var all=rs.RecordCount;
var pgAll=Math.ceil(rs.RecordCount/articleInPage);
if(articleInPage>all)return false;
var first='首页', last='尾页', next='下一', previous='上一';
var next10='下十', previous10='上十';
var url='?'+Request.ServerVariables("QUERY_STRING")+'&'+identifier+'=';
var re=new RegExp(identifier+'\=.*','i')
url=url.replace(re,identifier+'=').replace('?&','?').replace('&&','&');
if(!articleInPage)var articleInPage=10; obj.PageSize=articleInPage; // 设置每页大小
if(currentPage<1) currentPage=1; // 当前所在页
if(currentPage>pgAll) currentPage=pgAll;
rs.AbsolutePage=currentPage;
currentPage>1?Response.Write('<a href="'+url+'1">'+first+'</a> ')
:Response.Write('<span class="nonLink">'+first+'</span> ');
if(pgAll>pagelink)
currentPage>10?Response.Write('<a href="'+url+(currentPage-0-10-(currentPage%10)+1)+'">'+
previous10+'</a> ') :Response.Write('<span class="nonLink">'+previous10+'</span> ');
currentPage>1?Response.Write('<a href="'+url+(currentPage-1)+'">'+previous+'</a> ')
:Response.Write('<span class="nonLink">'+previous+'</span> ');
for(var i=0, temp=currentPage-(currentPage%pagelink)+1, temp_=''; i<pagelink; temp++, i++){
if(temp>pgAll) break;
temp==currentPage?Response.Write('<span class="curLink">'+temp+'</span> ')
:Response.Write('<a href="'+url+temp+'">'+temp+'</a> ');
}
currentPage<pgAll?Response.Write('<a href="'+url+(currentPage-0+1)+'">'+next+'</a> ')
:Response.Write('<span class="nonLink">'+next+'</span> ');
if(pgAll>pagelink)
currentPage<pgAll-9?Response.Write('<a href="'+url+(currentPage-0+10-(currentPage%10)+1)+'">'+
next10+'</a> ') :Response.Write('<span class="nonLink">'+next10+'</span> ');
currentPage!=pgAll?Response.Write(' <a href="'+url+pgAll+'">'+last+'</a>')
:Response.Write(' <span class="nonLink">'+last+'</span>');
},
//------------------------------------end list
// begin info
info:function(obj, articleInPage, pagelink){
/* 参数设置同上; */
if(!obj)return false;
if(obj.Eof||obj.Bof)return false;
Response.Write(articleInPage+'篇/页 ');
Response.Write(obj.AbsolutePage+'/'+obj.PageCount+'页 ');
Response.Write('共'+obj.RecordCount+'篇 ');
}
//------------------------------------end list
} // shawl.qiu code
//-----------------------------end object oPgnt-------------------------------//
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" " http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns=" http://www.w3.org/1999/xhtml">
<!-- DW6 -->
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>shawl.qiu template</title>
<style type="text/css">
/* <![CDATA[ */
.curLink{color:#ffccff;}
.nonLink{color:#CCCCCC;}
/* ]]> */
</style>
</head>
<body>
<%
var conn= "Provider=Microsoft.Jet.OLEDB.4.0;persist security info=false;Data source="+
Server.MapPath("/sqEditor/data/shawlqiu.mdb");
var page=Request.QueryString('page')>0? Request.QueryString('page'): 1;
var pageShow=20;
var rs=new ActiveXObject('adodb.recordset');
rs.Open("select * from shawlqiu_ order by articleid desc", conn, 1);
oPgnt.list(rs, pageShow, 10, page, 'page');
Response.Write('<br/>');
oPgnt.info(rs, pageShow, 10);
Response.Write('<p/>');
for(var i=0; i<pageShow; i++){
if(rs.Eof||rs.Bof) break;
Response.Write(rs('title')+' '+rs('articleid'));
Response.Write('<br/>');
rs.MoveNext
}
delete rs;
%>
</body>
</html>
2. JScript 记录集分页函数对象
linenum
<%@LANGUAGE="JAVASCRIPT" CODEPAGE="65001"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" " http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns=" http://www.w3.org/1999/xhtml">
<!-- DW6 -->
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>shawl.qiu template</title>
<style type="text/css">
/* <![CDATA[ */
.curLink{color:#ffccff;}
.nonLink{color:#CCCCCC;}
/* ]]> */
</style>
</head>
<body>
<%
var conn= "Provider=Microsoft.Jet.OLEDB.4.0;persist security info=false;Data source="+
Server.MapPath("/sqEditor/data/shawlqiu.mdb");
var page=Request.QueryString('page')>0? Request.QueryString('page'): 1;
var rs=new ActiveXObject('adodb.recordset');
rs.Open("select * from shawlqiu order by articleid desc", conn, 1);
var pgnt=new fPagination()
pgnt.list(rs, 20, 10, page, 'page');
Response.Write('<br/>')
pgnt.info(rs, 20, 10);
pgnt=null
rs=null;
//-----------------------------begin object fPagination-----------------------------//
function fPagination(){
//------------------------------------begin list
this.list=function(obj, articleInPage, pagelink, currentPage, identifier){
/*------------------------------------------------*\
* 服务端 JScript 记录集分页 函数对象 By shawl.qiu
* ----------------------
* 参数说明:
* obj: 对象, recordset 对象;
* articleInPage: 数值, 每页分页大小;
* pagelink: 数值, 显示页面链接数;
* currentPage: 数值, 当前 request 查询的 页位置.
* identifier: 字串, 访问分页 request 识别符.
\*------------------------------------------------*/
if(!obj)return false;
if(obj.Eof||obj.Bof)return false;
if(!articleInPage)var articleInPage=10;
if(!currentPage) var currentPage=1;
var all=rs.RecordCount;
var pgAll=Math.ceil(rs.RecordCount/articleInPage);
if(articleInPage>all)return false;
var first='首页', last='尾页', next='下一', previous='上一';
var next10='下十', previous10='上十';
var url='?'+Request.ServerVariables("QUERY_STRING")+'&'+identifier+'=';
var re=new RegExp(identifier+'\=.*','i')
url=url.replace(re,identifier+'=').replace('?&','?').replace('&&','&');
if(!articleInPage)var articleInPage=10; obj.PageSize=articleInPage; // 设置每页大小
if(currentPage<1) currentPage=1; // 当前所在页
if(currentPage>pgAll) currentPage=pgAll;
rs.AbsolutePage=currentPage;
currentPage>1?Response.Write('<a href="'+url+'1">'+first+'</a> ')
:Response.Write('<span class="nonLink">'+first+'</span> ');
if(pgAll>pagelink)
currentPage>10?Response.Write('<a href="'+url+(currentPage-0-10-(currentPage%10)+1)+'">'+
previous10+'</a> ') :Response.Write('<span class="nonLink">'+previous10+'</span> ');
currentPage>1?Response.Write('<a href="'+url+(currentPage-1)+'">'+previous+'</a> ')
:Response.Write('<span class="nonLink">'+previous+'</span> ');
for(var i=0, temp=currentPage-(currentPage%pagelink)+1, temp_=''; i<pagelink; temp++, i++){
if(temp>pgAll) break;
temp==currentPage?Response.Write('<span class="curLink">'+temp+'</span> ')
:Response.Write('<a href="'+url+temp+'">'+temp+'</a> ');
}
currentPage<pgAll?Response.Write('<a href="'+url+(currentPage-0+1)+'">'+next+'</a> ')
:Response.Write('<span class="nonLink">'+next+'</span> ');
if(pgAll>pagelink)
currentPage<pgAll-9?Response.Write('<a href="'+url+(currentPage-0+10-(currentPage%10)+1)+'">'+
next10+'</a> ') :Response.Write('<span class="nonLink">'+next10+'</span> ');
currentPage!=pgAll?Response.Write(' <a href="'+url+pgAll+'">'+last+'</a>')
:Response.Write(' <span class="nonLink">'+last+'</span>');
}
//------------------------------------end list
// begin info
this.info=function(obj, articleInPage, pagelink){
/* 参数设置同上; */
if(!obj)return false;
if(obj.Eof||obj.Bof)return false;
Response.Write(articleInPage+'篇/页 ');
Response.Write(obj.AbsolutePage+'/'+obj.PageCount+'页 ');
Response.Write('共'+obj.RecordCount+'篇 ');
}
//------------------------------------end list
} // shawl.qiu code
//-----------------------------end object fPagination-------------------------------//
%>
</body>
</html>