2010年04月03日 12:02 函數代碼: <% '分頁導航 Function showPageNav(a,b,c,d,e,f,g) '用法: 'showPageNav(當前頁,共有幾頁,連結參數,指定頁數的地址 '欄變量,顯示幾個連結,中數,當前頁文字背景顏色) if b>1 then url="?"&c&"&"&d&"=" '首頁、上一頁 if a<>1 then w("<a href='"&url&"1'>首頁</a> ") en=url&cstr(a-1) w("<a href='"&en&"'>上一頁</a> ") end if
if a<=f then '情況一:當前頁在前f頁 '首頁 1 2 3 4 5 [6] 7 8 9 10 尾頁 for i=1 to e if i>b then exit for en=url&cstr(i) if i=a then w("<font color='#FFFFFF' style='background-color:"&g&"'> "&cstr(i)&" </font> ") '當前頁加上背景色 else w("<a href='"&en&"'> "&cstr(i)&" </a> ") end if next elseif a>b-f then '情況二:當前頁在後f頁 '首頁 69 70 71 72 73 74 75 [76] 77 78 尾頁 j=b+1-e if j<0 then j=1 for i=j to b en=url&cstr(i) if i=a then w("<font color='#FFFFFF' style='background-color:"&g&"'> "&cstr(i)&" </font> ") '當前頁加上背景色 else w("<a href='"&en&"'> "&cstr(i)&" </a> ") end if next else '情況三:當前頁在中間 '首頁 31 32 33 34 [35] 36 37 38 39 40 尾頁 j=a-f for i=j to j+e-1 en=url&cstr(i) if i=a then w("<font color='#FFFFFF' style='background-color:"&g&"'> "&cstr(i)&" </font> ") '當前頁加上背景色 else w("<a href='"&en&"'> "&cstr(i)&" </a> ") end if next end if '下一頁、尾頁 if a<>b then en=url&cstr(a+1) w("<a href='"&en&"'>下一頁</a> ") en=url&cstr(b) w("<a href='"&en&"'>尾頁</a> ") end if else w(" ") end if End Function 'Response.Write的縮寫 Sub w(s) Response.Write(s) End Sub %>
使用方法: 在需要顯示分頁連結的地方插入ASP代碼塊調用函數: <%call showPageNav(3,20,"e=f","p",10,6,"#993300")%> 這些參數的意思是: 3表示當前頁是第三頁 20表示共有20頁 10表示顯示10個連結 6表示中間的數。 比如: 首頁 1 2 3 4 5 6 7 8 9 10 尾頁 首頁 1 2 3 4 5 6 7 8 9 10 尾頁 首頁 1 2 3 4 5 6 7 8 9 10 尾頁 首頁 1 2 3 4 5 6 7 8 9 10 尾頁 首頁 1 2 3 4 5 6 7 8 9 10 尾頁 首頁 1 2 3 4 5 6 7 8 9 10 尾頁 首頁 2 3 4 5 6 7 8 9 10 11 尾頁 首頁 3 4 5 6 7 8 9 10 11 12 尾頁 超過6後,滾動條後移。 "#993300"表示當前頁的背景顏色。 比如: 首頁 3 4 5 6 7 8 9 10 11 12 尾頁 "e=f"附加在url後的url變量 "p"表示指定當前頁的url變量為p 比如: e.asp?e=f&p=4
|