直接寫成函數(shù)的形式,如果輸出生成好的頁(yè)碼,然后又程序輸出或保存到文件中。
前十頁(yè)為一批,第十頁(yè)顯示1,2,3…10;第十一頁(yè)頁(yè)碼就變成了11,12…20
這種模式很多CMS都用到,比如5UCMS。函數(shù)名留點(diǎn)版權(quán)信息吧,cs=CatSeven
%
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""">首頁(yè)/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" url1id-1url2""">上一頁(yè)/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" url1iurl2""">"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" url1id+1url2""">下一頁(yè)/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" url1allurl2""">尾頁(yè)/a>"
csPage=tmp
end function
'DEBUG
for j=1 to 40
response.write "#Page"j":"csPage(j,40,"#TEST_","_View")"br />"
next
%>
生成效果如下:
#Page1:1 2 3 4 5 6 7 8 9 10 下一頁(yè) 尾頁(yè)
#Page2:首頁(yè) 上一頁(yè) 1 2 3 4 5 6 7 8 9 10 下一頁(yè) 尾頁(yè)
#Page3:首頁(yè) 上一頁(yè) 1 2 3 4 5 6 7 8 9 10 下一頁(yè) 尾頁(yè)
#Page4:首頁(yè) 上一頁(yè) 1 2 3 4 5 6 7 8 9 10 下一頁(yè) 尾頁(yè)
#Page5:首頁(yè) 上一頁(yè) 1 2 3 4 5 6 7 8 9 10 下一頁(yè) 尾頁(yè)
#Page6:首頁(yè) 上一頁(yè) 1 2 3 4 5 6 7 8 9 10 下一頁(yè) 尾頁(yè)
#Page7:首頁(yè) 上一頁(yè) 1 2 3 4 5 6 7 8 9 10 下一頁(yè) 尾頁(yè)
#Page8:首頁(yè) 上一頁(yè) 1 2 3 4 5 6 7 8 9 10 下一頁(yè) 尾頁(yè)
#Page9:首頁(yè) 上一頁(yè) 1 2 3 4 5 6 7 8 9 10 下一頁(yè) 尾頁(yè)
#Page10:首頁(yè) 上一頁(yè) 1 2 3 4 5 6 7 8 9 10 下一頁(yè) 尾頁(yè)
#Page11:首頁(yè) 上一頁(yè) 11 12 13 14 15 16 17 18 19 20 下一頁(yè) 尾頁(yè)
#Page12:首頁(yè) 上一頁(yè) 11 12 13 14 15 16 17 18 19 20 下一頁(yè) 尾頁(yè)
#Page13:首頁(yè) 上一頁(yè) 11 12 13 14 15 16 17 18 19 20 下一頁(yè) 尾頁(yè)
#Page14:首頁(yè) 上一頁(yè) 11 12 13 14 15 16 17 18 19 20 下一頁(yè) 尾頁(yè)
#Page15:首頁(yè) 上一頁(yè) 11 12 13 14 15 16 17 18 19 20 下一頁(yè) 尾頁(yè)
#Page16:首頁(yè) 上一頁(yè) 11 12 13 14 15 16 17 18 19 20 下一頁(yè) 尾頁(yè)
#Page17:首頁(yè) 上一頁(yè) 11 12 13 14 15 16 17 18 19 20 下一頁(yè) 尾頁(yè)
#Page18:首頁(yè) 上一頁(yè) 11 12 13 14 15 16 17 18 19 20 下一頁(yè) 尾頁(yè)
#Page19:首頁(yè) 上一頁(yè) 11 12 13 14 15 16 17 18 19 20 下一頁(yè) 尾頁(yè)
#Page20:首頁(yè) 上一頁(yè) 11 12 13 14 15 16 17 18 19 20 下一頁(yè) 尾頁(yè)
#Page21:首頁(yè) 上一頁(yè) 21 22 23 24 25 26 27 28 29 30 下一頁(yè) 尾頁(yè)
#Page22:首頁(yè) 上一頁(yè) 21 22 23 24 25 26 27 28 29 30 下一頁(yè) 尾頁(yè)
#Page23:首頁(yè) 上一頁(yè) 21 22 23 24 25 26 27 28 29 30 下一頁(yè) 尾頁(yè)
#Page24:首頁(yè) 上一頁(yè) 21 22 23 24 25 26 27 28 29 30 下一頁(yè) 尾頁(yè)
#Page25:首頁(yè) 上一頁(yè) 21 22 23 24 25 26 27 28 29 30 下一頁(yè) 尾頁(yè)
#Page26:首頁(yè) 上一頁(yè) 21 22 23 24 25 26 27 28 29 30 下一頁(yè) 尾頁(yè)
#Page27:首頁(yè) 上一頁(yè) 21 22 23 24 25 26 27 28 29 30 下一頁(yè) 尾頁(yè)
#Page28:首頁(yè) 上一頁(yè) 21 22 23 24 25 26 27 28 29 30 下一頁(yè) 尾頁(yè)
#Page29:首頁(yè) 上一頁(yè) 21 22 23 24 25 26 27 28 29 30 下一頁(yè) 尾頁(yè)
#Page30:首頁(yè) 上一頁(yè) 21 22 23 24 25 26 27 28 29 30 下一頁(yè) 尾頁(yè)
#Page31:首頁(yè) 上一頁(yè) 31 32 33 34 35 36 37 38 39 40 下一頁(yè) 尾頁(yè)
#Page32:首頁(yè) 上一頁(yè) 31 32 33 34 35 36 37 38 39 40 下一頁(yè) 尾頁(yè)
#Page33:首頁(yè) 上一頁(yè) 31 32 33 34 35 36 37 38 39 40 下一頁(yè) 尾頁(yè)
#Page34:首頁(yè) 上一頁(yè) 31 32 33 34 35 36 37 38 39 40 下一頁(yè) 尾頁(yè)
#Page35:首頁(yè) 上一頁(yè) 31 32 33 34 35 36 37 38 39 40 下一頁(yè) 尾頁(yè)
#Page36:首頁(yè) 上一頁(yè) 31 32 33 34 35 36 37 38 39 40 下一頁(yè) 尾頁(yè)
#Page37:首頁(yè) 上一頁(yè) 31 32 33 34 35 36 37 38 39 40 下一頁(yè) 尾頁(yè)
#Page38:首頁(yè) 上一頁(yè) 31 32 33 34 35 36 37 38 39 40 下一頁(yè) 尾頁(yè)
#Page39:首頁(yè) 上一頁(yè) 31 32 33 34 35 36 37 38 39 40 下一頁(yè) 尾頁(yè)
#Page40:首頁(yè) 上一頁(yè) 31 32 33 34 35 36 37 38 39 40
說(shuō)實(shí)話我并不是很喜歡這種分頁(yè)方式,我比較喜歡上次寫的那個(gè)。
如果不超過(guò)10頁(yè),比如共5頁(yè)。1,2,3,4,5;
如果最末頁(yè)減當(dāng)前頁(yè)碼不超過(guò)十,頁(yè)碼顯示最后10頁(yè);
其他的是前四后五的方法。直接給出代碼吧
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""">首頁(yè)/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" url1id-1url2""">上一頁(yè)/a> "
if alllt;10 or idlt;10 then
istart=1
if alllt;10 then iend=all else iend=10
elseif all-idlt;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" url1iurl2""">"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" url1id+1url2""">下一頁(yè)/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" url1allurl2""">尾頁(yè)/a>"
csPage1=tmp
end function
for j=1 to 40
response.write "#Page"j":"csPage1(j,40,"#TEST_","_View")"br />"
next
生成效果如下:
#Page1:1 2 3 4 5 6 7 8 9 10 下一頁(yè) 尾頁(yè)
#Page2:首頁(yè) 上一頁(yè) 1 2 3 4 5 6 7 8 9 10 下一頁(yè) 尾頁(yè)
#Page3:首頁(yè) 上一頁(yè) 1 2 3 4 5 6 7 8 9 10 下一頁(yè) 尾頁(yè)
#Page4:首頁(yè) 上一頁(yè) 1 2 3 4 5 6 7 8 9 10 下一頁(yè) 尾頁(yè)
#Page5:首頁(yè) 上一頁(yè) 1 2 3 4 5 6 7 8 9 10 下一頁(yè) 尾頁(yè)
#Page6:首頁(yè) 上一頁(yè) 1 2 3 4 5 6 7 8 9 10 下一頁(yè) 尾頁(yè)
#Page7:首頁(yè) 上一頁(yè) 1 2 3 4 5 6 7 8 9 10 下一頁(yè) 尾頁(yè)
#Page8:首頁(yè) 上一頁(yè) 1 2 3 4 5 6 7 8 9 10 下一頁(yè) 尾頁(yè)
#Page9:首頁(yè) 上一頁(yè) 1 2 3 4 5 6 7 8 9 10 下一頁(yè) 尾頁(yè)
#Page10:首頁(yè) 上一頁(yè) 6 7 8 9 10 11 12 13 14 15 下一頁(yè) 尾頁(yè)
#Page11:首頁(yè) 上一頁(yè) 7 8 9 10 11 12 13 14 15 16 下一頁(yè) 尾頁(yè)
#Page12:首頁(yè) 上一頁(yè) 8 9 10 11 12 13 14 15 16 17 下一頁(yè) 尾頁(yè)
#Page13:首頁(yè) 上一頁(yè) 9 10 11 12 13 14 15 16 17 18 下一頁(yè) 尾頁(yè)
#Page14:首頁(yè) 上一頁(yè) 10 11 12 13 14 15 16 17 18 19 下一頁(yè) 尾頁(yè)
#Page15:首頁(yè) 上一頁(yè) 11 12 13 14 15 16 17 18 19 20 下一頁(yè) 尾頁(yè)
#Page16:首頁(yè) 上一頁(yè) 12 13 14 15 16 17 18 19 20 21 下一頁(yè) 尾頁(yè)
#Page17:首頁(yè) 上一頁(yè) 13 14 15 16 17 18 19 20 21 22 下一頁(yè) 尾頁(yè)
#Page18:首頁(yè) 上一頁(yè) 14 15 16 17 18 19 20 21 22 23 下一頁(yè) 尾頁(yè)
#Page19:首頁(yè) 上一頁(yè) 15 16 17 18 19 20 21 22 23 24 下一頁(yè) 尾頁(yè)
#Page20:首頁(yè) 上一頁(yè) 16 17 18 19 20 21 22 23 24 25 下一頁(yè) 尾頁(yè)
#Page21:首頁(yè) 上一頁(yè) 17 18 19 20 21 22 23 24 25 26 下一頁(yè) 尾頁(yè)
#Page22:首頁(yè) 上一頁(yè) 18 19 20 21 22 23 24 25 26 27 下一頁(yè) 尾頁(yè)
#Page23:首頁(yè) 上一頁(yè) 19 20 21 22 23 24 25 26 27 28 下一頁(yè) 尾頁(yè)
#Page24:首頁(yè) 上一頁(yè) 20 21 22 23 24 25 26 27 28 29 下一頁(yè) 尾頁(yè)
#Page25:首頁(yè) 上一頁(yè) 21 22 23 24 25 26 27 28 29 30 下一頁(yè) 尾頁(yè)
#Page26:首頁(yè) 上一頁(yè) 22 23 24 25 26 27 28 29 30 31 下一頁(yè) 尾頁(yè)
#Page27:首頁(yè) 上一頁(yè) 23 24 25 26 27 28 29 30 31 32 下一頁(yè) 尾頁(yè)
#Page28:首頁(yè) 上一頁(yè) 24 25 26 27 28 29 30 31 32 33 下一頁(yè) 尾頁(yè)
#Page29:首頁(yè) 上一頁(yè) 25 26 27 28 29 30 31 32 33 34 下一頁(yè) 尾頁(yè)
#Page30:首頁(yè) 上一頁(yè) 26 27 28 29 30 31 32 33 34 35 下一頁(yè) 尾頁(yè)
#Page31:首頁(yè) 上一頁(yè) 30 31 32 33 34 35 36 37 38 39 40 下一頁(yè) 尾頁(yè)
#Page32:首頁(yè) 上一頁(yè) 30 31 32 33 34 35 36 37 38 39 40 下一頁(yè) 尾頁(yè)
#Page33:首頁(yè) 上一頁(yè) 30 31 32 33 34 35 36 37 38 39 40 下一頁(yè) 尾頁(yè)
#Page34:首頁(yè) 上一頁(yè) 30 31 32 33 34 35 36 37 38 39 40 下一頁(yè) 尾頁(yè)
#Page35:首頁(yè) 上一頁(yè) 30 31 32 33 34 35 36 37 38 39 40 下一頁(yè) 尾頁(yè)
#Page36:首頁(yè) 上一頁(yè) 30 31 32 33 34 35 36 37 38 39 40 下一頁(yè) 尾頁(yè)
#Page37:首頁(yè) 上一頁(yè) 30 31 32 33 34 35 36 37 38 39 40 下一頁(yè) 尾頁(yè)
#Page38:首頁(yè) 上一頁(yè) 30 31 32 33 34 35 36 37 38 39 40 下一頁(yè) 尾頁(yè)
#Page39:首頁(yè) 上一頁(yè) 30 31 32 33 34 35 36 37 38 39 40 下一頁(yè) 尾頁(yè)
#Page40:首頁(yè) 上一頁(yè) 30 31 32 33 34 35 36 37 38 39 40
上面的代碼在2009-2010年寫過(guò)簡(jiǎn)單個(gè)兩個(gè)分頁(yè)(調(diào)取頁(yè)碼的函數(shù)):
現(xiàn)在看有點(diǎn)亂了,最近有重新整理了下代碼,重寫了ASP的分頁(yè)代碼,生成的分頁(yè)代碼兼容BootStrap。代碼如下:
'PageinationRecordSet 如果返回false,說(shuō)明 Adodb.RecrodSet集 為空
'RecordSet Adodb.RecrodSet集
'PageId 當(dāng)前所在頁(yè)
'PageSize 每頁(yè)顯示多少條?
'*PageCount 返回頁(yè)碼總數(shù)
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 當(dāng)前所在頁(yè)
'PageCount 頁(yè)碼總數(shù)
'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) """> 首頁(yè) /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) """>上一頁(yè)/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) """>下一頁(yè)/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) """>尾頁(yè)/a>/li>"
PageinationPageList = codeTemp "/ul>"
end if
end function
測(cè)試代碼:
pgId = Request.QueryString("pageid") '當(dāng)前頁(yè)碼
pgSize = 10 '每頁(yè)大小
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
'列表內(nèi)容
Rs.MoveNext
loop
end if
Rs.Close
'共 pgCount 頁(yè)
response.write PageinationPageList(pgId, pgCount, "./list.asp?pageid={pg}") '輸出分頁(yè)代碼
到此這篇關(guān)于完美的ASP分頁(yè)腳本代碼的文章就介紹到這了,更多相關(guān)ASP分頁(yè)內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!