在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
直接写成函数的形式,如果输出生成好的页码,然后又程序输出或保存到文件中。 前十页为一批,第十页显示1,2,3…10;第十一页页码就变成了11,12…20 <% function csPage(id,all,url1,url2) if id<>1 then tmp="<a href=""" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" &url1&"1"&url2&""">首页</a> <a href=""" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" &url1&id-1&url2&""">上一页</a>" istart=((id-1)\10)*10+1 if(all-id)>9 then iend=((id-1)\10)*10+10 else iend=all end if for i=istart to iend if i=id then tmp=tmp&"<span>"&i&"</span> " else tmp=tmp&"<a href=""" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" &url1&i&url2&""">"&i&"</a> " end if next if id<>all then tmp=tmp&"<a href=""" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" &url1&id+1&url2&""">下一页</a> <a href=""" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" &url1&all&url2&""">尾页</a>" csPage=tmp end function 'DEBUG for j=1 to 40 response.write "#Page"&j&":"&csPage(j,40,"#TEST_","_View")&"<br />" next %> 生成效果如下: 说实话我并不是很喜欢这种分页方式,我比较喜欢上次写的那个。 function csPage1(id,all,url1,url2) if id<>1 then tmp="<a href=""" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" &url1&"1"&url2&""">首页</a> <a href=""" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" &url1&id-1&url2&""">上一页</a> " if all<10 or id<10 then istart=1 if all<10 then iend=all else iend=10 elseif all-id<10 then istart=all-10 iend=all else istart=id-4 iend=id+5 end if for i=istart to iend if i=id then tmp=tmp&"<span>"&i&"</span> " else tmp=tmp&"<a href=""" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" &url1&i&url2&""">"&i&"</a> " end if next if id<>all then tmp=tmp&"<a href=""" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" &url1&id+1&url2&""">下一页</a> <a href=""" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" &url1&all&url2&""">尾页</a>" csPage1=tmp end function for j=1 to 40 response.write "#Page"&j&":"&csPage1(j,40,"#TEST_","_View")&"<br />" next 生成效果如下: 上面的代码在2009-2010年写过简单个两个分页(调取页码的函数): 现在看有点乱了,最近有重新整理了下代码,重写了ASP的分页代码,生成的分页代码兼容BootStrap。代码如下: 'PageinationRecordSet 如果返回false,说明 Adodb.RecrodSet集 为空 'RecordSet Adodb.RecrodSet集 'PageId 当前所在页 'PageSize 每页显示多少条? '*PageCount 返回页码总数 function PageinationRecordSet(byref RecordSet,byref PageId,byval PageSize,byref PageCount) if RecordSet.eof then PageinationRecordSet = false else RecordSet.PageSize = PageSize PageCount = RecordSet.PageCount if PageId > PageCount then PageId = PageCount RecordSet.absolutePage = PageId PageinationRecordSet = true end if end function 'PageId 当前所在页 'PageCount 页码总数 'urlTemplate 链接模板 function PageinationPageList(byval PageId,byval PageCount,byval urlTemplate) dim codeTemp,iPage if PageCount > 0 then codeTemp = "<ul class=""pagination"">" if PageId <= 1 then codeTemp = codeTemp & "<li class=""disabled"">" else codeTemp = codeTemp & "<li>" codeTemp = codeTemp & "<a href=""" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" & replace(urlTemplate,"{pg}",1) & """> 首页 </a></li>" if PageId <= 1 then codeTemp = codeTemp & "<li class=""disabled"">" else codeTemp = codeTemp & "<li>" codeTemp = codeTemp & "<a href=""" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" & replace(urlTemplate,"{pg}",PageId-1) & """>上一页</a></li>" for iPage = PageId - 5 to PageId + 5 if iPage = PageId then codeTemp = codeTemp & "<li class=""active""><a href=""" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" & replace(urlTemplate,"{pg}",iPage) & """>" & iPage & "</a></li>" elseif iPage < PageId and iPage > 0 then codeTemp = codeTemp & "<li><a href=""" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" & replace(urlTemplate,"{pg}",iPage) & """>" & iPage & "</a></li>" elseif iPage > PageId and iPage <= PageCount then codeTemp = codeTemp & "<li><a href=""" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" & replace(urlTemplate,"{pg}",iPage) & """>" & iPage & "</a></li>" end if next if PageId >= PageCount then codeTemp = codeTemp & "<li class=""disabled"">" else codeTemp = codeTemp & "<li>" codeTemp = codeTemp & "<a href=""" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" & replace(urlTemplate,"{pg}",PageId + 1) & """>下一页</a></li>" if PageId >= PageCount then codeTemp = codeTemp & "<li class=""disabled"">" else codeTemp = codeTemp & "<li>" codeTemp = codeTemp & "<a href=""" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" & replace(urlTemplate,"{pg}",PageCount) & """>尾页</a></li>" PageinationPageList = codeTemp & "</ul>" end if end function 测试代码: pgId = Request.QueryString("pageid") '当前页码 pgSize = 10 '每页大小 rsId = 0 Rs.Open Query,Conn,1,1 if PageinationRecordSet(Rs, pgId, pgSize, pgCount) then do while not Rs.Eof and rsId < pgSize rsId = rsId + 1 '列表内容 Rs.MoveNext loop end if Rs.Close '共 pgCount 页 response.write PageinationPageList(pgId, pgCount, "./list.asp?pageid={pg}") '输出分页代码 到此这篇关于完美的ASP分页脚本代码的文章就介绍到这了,更多相关ASP分页内容请搜索极客世界以前的文章或继续浏览下面的相关文章希望大家以后多多支持极客世界! |
请发表评论