服务端 JScript 记录集分页函数/对象 By shawl.qiu

服务端 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.youkuaiyun.com/btbtd/archive/2006/05/31/765595.aspx

vbs 文章分页: 
ASP 通用文章分页函数(非记录集分页), 返回多个结果, 字典实现 By shawl.qiu
URL:    http://blog.youkuaiyun.com/btbtd/archive/2006/09/04/1175126.aspx

目录:
1. JScript 记录集分页对象
2. JScript 记录集分页函数对象

shawl.qiu 
2006-11-26
http://blog.youkuaiyun.com/btbtd

1. JScript 记录集分页对象
  1. linenum
  2. <%@LANGUAGE="JAVASCRIPT" CODEPAGE="65001"%>
  3. <%    
  4.     //-----------------------------begin object oPgnt-----------------------------//
  5.     var oPgnt={
  6.         //------------------------------------begin list
  7.         list:function(obj, articleInPage, pagelink, currentPage, identifier){
  8.         /*------------------------------------------------*/
  9.          * 服务端 JScript 记录集分页对象 By shawl.qiu
  10.          * ----------------------
  11.          * 参数说明:
  12.          * obj: 对象, recordset 对象;
  13.          * articleInPage: 数值, 每页分页大小;
  14.          * pagelink: 数值, 显示页面链接数;
  15.          * currentPage: 数值, 当前 request 查询的 页位置.
  16.          * identifier: 字串, 访问分页 request 识别符.
  17.         /*------------------------------------------------*/
  18.             if(!obj)return false;
  19.             if(obj.Eof||obj.Bof)return false;
  20.             if(!articleInPage)var articleInPage=10;
  21.             if(!currentPage) var currentPage=1;
  22.             
  23.             var all=rs.RecordCount;
  24.             var pgAll=Math.ceil(rs.RecordCount/articleInPage);
  25.             
  26.             if(articleInPage>all)return false;
  27.             
  28.             var first='首页', last='尾页', next='下一', previous='上一';
  29.             var next10='下十', previous10='上十';
  30.             
  31.             var url='?'+Request.ServerVariables("QUERY_STRING")+'&'+identifier+'=';
  32.             var re=new RegExp(identifier+'/=.*','i')
  33.                 url=url.replace(re,identifier+'=').replace('?&','?').replace('&&','&');
  34.             
  35.             if(!articleInPage)var articleInPage=10; obj.PageSize=articleInPage; // 设置每页大小
  36.             if(currentPage<1) currentPage=1; // 当前所在页
  37.             if(currentPage>pgAll) currentPage=pgAll;
  38.                 rs.AbsolutePage=currentPage;
  39.             
  40.             currentPage>1?Response.Write('<a href="'+url+'1">'+first+'</a> ')
  41.             :Response.Write('<span class="nonLink">'+first+'</span> ');
  42.             
  43.             if(pgAll>pagelink)
  44.             currentPage>10?Response.Write('<a href="'+url+(currentPage-0-10-(currentPage%10)+1)+'">'+
  45.             previous10+'</a> ') :Response.Write('<span class="nonLink">'+previous10+'</span> ');
  46.             
  47.             currentPage>1?Response.Write('<a href="'+url+(currentPage-1)+'">'+previous+'</a> ')
  48.             :Response.Write('<span class="nonLink">'+previous+'</span> ');
  49.             
  50.             for(var i=0, temp=currentPage-(currentPage%pagelink)+1, temp_=''; i<pagelink; temp++, i++){
  51.                 if(temp>pgAll) break;
  52.                 temp==currentPage?Response.Write('<span class="curLink">'+temp+'</span> ')
  53.                 :Response.Write('<a href="'+url+temp+'">'+temp+'</a> ');
  54.             }
  55.             
  56.             currentPage<pgAll?Response.Write('<a href="'+url+(currentPage-0+1)+'">'+next+'</a> ')
  57.             :Response.Write('<span class="nonLink">'+next+'</span> ');
  58.             
  59.             if(pgAll>pagelink)
  60.             currentPage<pgAll-9?Response.Write('<a href="'+url+(currentPage-0+10-(currentPage%10)+1)+'">'+
  61.             next10+'</a> ') :Response.Write('<span class="nonLink">'+next10+'</span> ');
  62.             
  63.             currentPage!=pgAll?Response.Write(' <a href="'+url+pgAll+'">'+last+'</a>')
  64.             :Response.Write(' <span class="nonLink">'+last+'</span>');
  65.         },
  66.         //------------------------------------end list
  67.         // begin info
  68.         info:function(obj, articleInPage, pagelink){
  69.         /* 参数设置同上;  */
  70.             if(!obj)return false;
  71.             if(obj.Eof||obj.Bof)return false;
  72.             Response.Write(articleInPage+'篇/页 ');
  73.             Response.Write(obj.AbsolutePage+'/'+obj.PageCount+'页 ');
  74.             Response.Write('共'+obj.RecordCount+'篇 ');
  75.         }
  76.         //------------------------------------end list
  77.     } // shawl.qiu code
  78.     //-----------------------------end object oPgnt-------------------------------//
  79. %>
  80. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" " http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  81. <html xmlns=" http://www.w3.org/1999/xhtml">
  82. <!-- DW6 -->
  83. <head>
  84. <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  85. <title>shawl.qiu template</title>
  86. <style type="text/css">
  87. /* <![CDATA[ */
  88.     .curLink{color:#ffccff;}
  89.     .nonLink{color:#CCCCCC;}
  90. /* ]]> */
  91. </style>
  92. </head>
  93. <body>
  94. <%    
  95.     var conn= "Provider=Microsoft.Jet.OLEDB.4.0;persist security info=false;Data source="+
  96.     Server.MapPath("/sqEditor/data/shawlqiu.mdb");
  97.     
  98.     var page=Request.QueryString('page')>0? Request.QueryString('page'): 1;
  99.     var pageShow=20;
  100.     
  101.     var rs=new ActiveXObject('adodb.recordset');
  102.         rs.Open("select * from shawlqiu_ order by articleid desc", conn, 1);
  103.     
  104.         oPgnt.list(rs, pageShow, 10, page, 'page');
  105.         Response.Write('<br/>');
  106.         oPgnt.info(rs, pageShow, 10);
  107.         Response.Write('<p/>');
  108.         
  109.         for(var i=0; i<pageShow; i++){
  110.             if(rs.Eof||rs.Bof) break;
  111.             Response.Write(rs('title')+' '+rs('articleid'));
  112.             Response.Write('<br/>');
  113.             rs.MoveNext
  114.         }
  115.     delete rs;
  116. %>
  117. </body>
  118. </html>

2. JScript 记录集分页函数对象
  1. linenum
  2. <%@LANGUAGE="JAVASCRIPT" CODEPAGE="65001"%>
  3. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" " http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  4. <html xmlns=" http://www.w3.org/1999/xhtml">
  5. <!-- DW6 -->
  6. <head>
  7. <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  8. <title>shawl.qiu template</title>
  9. <style type="text/css">
  10. /* <![CDATA[ */
  11.     .curLink{color:#ffccff;}
  12.     .nonLink{color:#CCCCCC;}
  13. /* ]]> */
  14. </style>
  15. </head>
  16. <body>
  17. <%    
  18.     var conn= "Provider=Microsoft.Jet.OLEDB.4.0;persist security info=false;Data source="+
  19.     Server.MapPath("/sqEditor/data/shawlqiu.mdb");
  20.     
  21.     var page=Request.QueryString('page')>0? Request.QueryString('page'): 1;
  22.     
  23.     var rs=new ActiveXObject('adodb.recordset');
  24.         rs.Open("select * from shawlqiu order by articleid desc", conn, 1);
  25.     
  26.         var pgnt=new fPagination()
  27.             pgnt.list(rs, 20, 10, page, 'page');
  28.             Response.Write('<br/>')
  29.             pgnt.info(rs, 20, 10);
  30.             pgnt=null
  31.             
  32.         rs=null;
  33.     
  34.     //-----------------------------begin object fPagination-----------------------------//
  35.     function fPagination(){
  36.         //------------------------------------begin list
  37.         this.list=function(obj, articleInPage, pagelink, currentPage, identifier){
  38.         /*------------------------------------------------*/
  39.          * 服务端 JScript 记录集分页 函数对象 By shawl.qiu
  40.          * ----------------------
  41.          * 参数说明:
  42.          * obj: 对象, recordset 对象;
  43.          * articleInPage: 数值, 每页分页大小;
  44.          * pagelink: 数值, 显示页面链接数;
  45.          * currentPage: 数值, 当前 request 查询的 页位置.
  46.          * identifier: 字串, 访问分页 request 识别符.
  47.         /*------------------------------------------------*/
  48.             if(!obj)return false;
  49.             if(obj.Eof||obj.Bof)return false;
  50.             if(!articleInPage)var articleInPage=10;
  51.             if(!currentPage) var currentPage=1;
  52.             
  53.             var all=rs.RecordCount;
  54.             var pgAll=Math.ceil(rs.RecordCount/articleInPage);
  55.             
  56.             if(articleInPage>all)return false;
  57.             
  58.             var first='首页', last='尾页', next='下一', previous='上一';
  59.             var next10='下十', previous10='上十';
  60.             
  61.             var url='?'+Request.ServerVariables("QUERY_STRING")+'&'+identifier+'=';
  62.             var re=new RegExp(identifier+'/=.*','i')
  63.                 url=url.replace(re,identifier+'=').replace('?&','?').replace('&&','&');
  64.             
  65.             if(!articleInPage)var articleInPage=10; obj.PageSize=articleInPage; // 设置每页大小
  66.             if(currentPage<1) currentPage=1; // 当前所在页
  67.             if(currentPage>pgAll) currentPage=pgAll;
  68.                 rs.AbsolutePage=currentPage;
  69.             
  70.             currentPage>1?Response.Write('<a href="'+url+'1">'+first+'</a> ')
  71.             :Response.Write('<span class="nonLink">'+first+'</span> ');
  72.             
  73.             if(pgAll>pagelink)
  74.             currentPage>10?Response.Write('<a href="'+url+(currentPage-0-10-(currentPage%10)+1)+'">'+
  75.             previous10+'</a> ') :Response.Write('<span class="nonLink">'+previous10+'</span> ');
  76.             
  77.             currentPage>1?Response.Write('<a href="'+url+(currentPage-1)+'">'+previous+'</a> ')
  78.             :Response.Write('<span class="nonLink">'+previous+'</span> ');
  79.             
  80.             for(var i=0, temp=currentPage-(currentPage%pagelink)+1, temp_=''; i<pagelink; temp++, i++){
  81.                 if(temp>pgAll) break;
  82.                 temp==currentPage?Response.Write('<span class="curLink">'+temp+'</span> ')
  83.                 :Response.Write('<a href="'+url+temp+'">'+temp+'</a> ');
  84.             }
  85.             
  86.             currentPage<pgAll?Response.Write('<a href="'+url+(currentPage-0+1)+'">'+next+'</a> ')
  87.             :Response.Write('<span class="nonLink">'+next+'</span> ');
  88.             
  89.             if(pgAll>pagelink)
  90.             currentPage<pgAll-9?Response.Write('<a href="'+url+(currentPage-0+10-(currentPage%10)+1)+'">'+
  91.             next10+'</a> ') :Response.Write('<span class="nonLink">'+next10+'</span> ');
  92.             
  93.             currentPage!=pgAll?Response.Write(' <a href="'+url+pgAll+'">'+last+'</a>')
  94.             :Response.Write(' <span class="nonLink">'+last+'</span>');
  95.         }
  96.         //------------------------------------end list
  97.         // begin info
  98.         this.info=function(obj, articleInPage, pagelink){
  99.         /* 参数设置同上;  */
  100.             if(!obj)return false;
  101.             if(obj.Eof||obj.Bof)return false;
  102.             Response.Write(articleInPage+'篇/页 ');
  103.             Response.Write(obj.AbsolutePage+'/'+obj.PageCount+'页 ');
  104.             Response.Write('共'+obj.RecordCount+'篇 ');
  105.         }
  106.         //------------------------------------end list
  107.     } // shawl.qiu code
  108.     //-----------------------------end object fPagination-------------------------------//
  109. %>
  110. </body>
  111. </html>


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值