关闭

ASP VBScript 分页函数 by Stabx, 第三版

标签: vbscriptaspurlstring数据库query
3254人阅读 评论(0) 收藏 举报
分类:
标题: ASP VBScript 分页函数 by Stabx, 第三版

正文:

QUOTE:

ASP VBScript 分页函数 by Stabx, 第三版

作用: 
翻页导航, 显示数据请另外处理

说明:
简化简化再简化, 只需输入 '''/// call fPageCount(连接名,每页总数,开始数,号码导航链接数) ///'''
详细如: call fPageCount(rs,50,1,10)
 
本版实现了不需输入 URL 就可以自动获取 URL 的功能
文本框翻页功能也实现了智能化, 不需指定 URL, 前提是客户端没关闭 JS (相信不会有太多人跟我一样, 通常浏览网页都关闭 JS, 只在调试时使用)
本版尽可能的没用 联字符(&), 该字符很费时

导航预览:
首页 上十 上一 81 82 83 84 85 86 87 88 89 90 下一 下十 尾页 转到:___
50篇/页 88/831页 共 41503篇

shawl.qiu
2006-5-31

CODE:

'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
' subject    : ASP VBScript 分页函数 by Stabx, 第三版
'
' writer    : Stabx<[email]shawl.qiu@gmail.com[/email]>
'
' blog        : http://blog.csdn.net/btbtd / http://btbtd.exblog.jp/ 
'
' blog/site    : Phoenix.GI - P.GI / / 绿色学院 - Green Institute
'
' date        : 2006-5-31
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
'简化简化再简化, 只需输入 '''/// call fPageCount(连接名,每页总数,开始数,号码导航链接数) ///'''
'本版实现了不需输入 URL 就可以自动获取 URL 的功能
'文本框翻页功能也实现了智能化, 不需指定 URL, 前提是客户端没关闭 JS (相信不会有太多人跟我一样, 通常浏览网页都关闭 JS, 只在调试时使用)
'本版尽可能的没用 联字符(&), 该字符很费时
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
' 使用例子
'sample call '''// call fPageCount(rs,50,1,10) //'''
'sample call '''// call fPageCount(otherRSname,50,1,10) //'''
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
'参数使用说明
''''''''''''''''''''''''''''''''''''''
'rs                 |     数据库表连接名
'repeatnum            |    每页显示记录总数
'startbynum            |    从多少开始循环显示
'numlink            |    显示数字链接导航数目
'''''''''''''''''''''
'全例: call fPageCount(rs,50,1,10)
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
function fPageCount(rs,repeatnum,startbynum,numlink)

    toF_="首页"
     toP10_=" 上十"
     toP1_=" 上一"
     toN1_=" 下一"
     toN10_=" 下十"
     toL_="尾页"
    
     if not rs.eof  then
             rrc_=rs.recordcount
     end if

    if (not rs.eof or not rs.bof) and rrc_>repeatnum then '记录总数大于每页总数才显示分页链接
    
             rqq_=request.ServerVariables("QUERY_STRING") '获取 URL 查询串, 并筛选所需
             pv_=request("pageview") '翻页查询字符
         if rqq_="" then
             url="?pageview="
         elseif instr(rqq_,"pageview")<>0 then    
             url="?"&replace(rqq_,"pageview="&pv_,"")&"pageview=" '不要试图把 pageview= 放进 replace 里
         else
             url="?"&replace(rqq_,"&pageview="&pv_,"")&"&pageview=" '同上
         end if
            
             pageview=CInt(Request("pageview"))  '读取 URL 页号
             rs.PageSize=repeatnum '定义每页显示记录数
        
         If pageview<=0 Then pageview=1 '如果 pageview 小于或等于0, 返回值1
             If pageview>rs.PageCount Then pageview=rs.PageCount ' 如果 pageview 大于分页总数, 返回分页末页值  
             rs.AbsolutePage=pageview '定义当前页码
            
             cPageNo=rs.AbsolutePage
             tpagecount=rs.pagecount
        
             If cPageNo<1 Then cPageNo=1  '如果页数小于 1, 默认为 1; 当前页, cPageNo = Current Page NO.
             If tPageCount<1 Then tPageCount=1  
             If cPageNo>tPageCount Then cPageNo=tPageCount   
                 Dim NaviLength  
                 NaviLength=numlink ' 显示数字链接数
                 Dim StartPage,EndPage ' 定义当前页, 开始页, 结束页
                 StartPage=(cPageNo/NaviLength)*NaviLength+1  '为开始页赋值
                
             if pageview=1 then '判断是否首页, 如果是首页不添加链接,反之添加.
                 Response.Write "<font color=""#CCCCCC"">"
                 response.write toF_
                 response.write "</font> "
             Else  
                 Response.Write "<a href="""
                 response.write url
                 response.write "1#anchor"">"
                 response.write toF_
                 response.write "</a> "
             End If   
            
             If (cPageNo Mod NaviLength)=0 Then StartPage=StartPage-NaviLength   
                 EndPage=StartPage+NaviLength-1                  
             If EndPage>tPageCount Then EndPage=tPageCount   
    
             If StartPage>1 Then '向后移动一分页, 十页为一分页, 并且以 1, 11, 21... 为每页的开始页数
                 Response.Write "<a href="""
                 response.write url
                 response.write (cPageNo-(cPageNo mod 10)-NaviLength+1)
                 response.write "#anchor"">"
                 response.write toP10_
                 response.write "</a> "  
             Else  
                 Response.Write "<font color=""#CCCCCC"">"
                 response.write toP10_
                 response.write "</font> "  
             End If  
    
             If pageview <> 1 and pageview <>0 Then '后移一页
                 Response.Write "<a href="""
                 response.write url
                 response.write (pageview-1)
                 response.write "#anchor"">"
                 response.write toP1_
                 response.write "</a> "  
             Else  
                 Response.Write "<font color=""#CCCCCC"">"
                 response.write toP1_
                 response.write "</font> "  
             End If  
    
             For startbynum=StartPage To EndPage  
                 If startbynum=cPageNo Then  
                     Response.Write "<b class=""gray"">"
                     response.write startbynum
                     response.write "</b> "  
                 Else  
                     Response.Write "<a href="""
                     response.write url
                     response.write startbynum
                     response.write "#anchor"">" 
                     response.write startbynum
                     response.write  "</a> "  
                 End If  
             Next  
    
             If pageview <> rs.PageCount and pageview <>0 Then '前移一页
                 Response.Write " <a href="""
                 response.write url
                 response.write (pageview+1)
                 response.write "#anchor"">"
                 response.write toN1_
                 response.write "</a> "  
             Else  
                 Response.Write "<font color=""#CCCCCC"">"
                 response.write toN1_
                 response.write "</font> "  
             End If  
    
             If EndPage<tpagecount Then  '向前移动一分页, 十页为一分页, 并且以 1, 11, 21 为每页的开始页数
                 Response.Write " <a href="""
                 response.write url
                 response.write (cPageNo-(cPageNo mod 10)+NaviLength+1)
                 response.write "#anchor"">"
                 response.write toN10_
                 response.write "</a> "  
             Else  
                 Response.Write " <font color=""#CCCCCC"">"
                 response.write toN10_
                 response.write "</font> "  
             End If  
    
             if  rs.PageCount<>pageview then '判断是否尾页
                 Response.Write "<a href="""
                 response.write url
                 response.write tpagecount
                 response.write "#anchor"">"
                 response.write toL_
                 response.write "</a>"  
             Else  
                 Response.Write "<font color=""#CCCCCC"">"
                 response.write toL_
                 response.write "</font>" 
             End If  
                 response.write " 转到:<input TYPE=""text"" class=""jumpinput"" onMouseMove=""this.focus();this.select();"" onkeypress=""ckKeyPress(this.value);"" ><br/>"
                 '页面信息
                 response.write repeatnum
                 response.write "篇/页 "
                 response.write cPageNo
                 response.write "/"
                 response.write tPageCount
                 response.write "页 共 "
                 response.write rrc_
                 response.write "篇<script>function ckKeyPress(jumpto){if(window.event.keyCode==13) {window.location.href="""
                 response.write url
                 response.write """+jumpto+""#anchor""}}</script>"
             elseif (not rs.eof or not rs.bof) and rrc_<=repeatnum then 
                 response.write "<div class=font12px>共 "
                 response.write rrc_
                 response.write " 篇</div>"
             end if
end function

0
0

查看评论
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场