科技行者

行者学院 转型私董会 科技行者专题报道 网红大战科技行者

知识库

知识库 安全导航

至顶网软件频道服务端 JScript 记录集分页函数/对象 By shawl.qiu

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

  • 扫一扫
    分享文章到微信

  • 扫一扫
    关注官方公众号
    至顶头条

这次用 JScript 写了两个分页程序, 一个是 Jscript 对象, 一个是Jscript 函数对象, 我比较喜欢 Jscript 对象, 不需要像函数对象那样 new obj 使用.

作者:btbtd 来源:CSDN 2008年3月17日

关键字: 分页函数 jscript java

  • 评论
  • 分享微博
  • 分享邮件
说明:
分页其实很简单的, 我都写了好几个分页函数了...

感觉 JScript 写代码比 VBScript 方便不少, 基本恋上用 类C 语法写代码, BASIC 语法快看不懂了....

唉, 没啥好说的, 这次用 JScript 写了两个分页程序, 一个是 Jscript 对象, 一个是Jscript 函数对象, 我比较喜欢 Jscript 对象, 不需要像函数对象那样 new obj 使用. 

注: 对象需要在使用之前定义, 函数对象可在使用后定义.

广告时间:
我的 HTML 编辑器已经写好了, 取名 sqEditor, 支持 Opera, IE, Firefox. 
暂不公开.



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



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

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

    如果您非常迫切的想了解IT领域最新产品与技术信息,那么订阅至顶网技术邮件将是您的最佳途径之一。

    重磅专题
    往期文章
    最新文章