Sub ShowPageNum(RecordNum,PSize,P,HrefStr)
'根据数据总量、每页显示量、页码生成页面导航
'PecordNum 数据总数
'PSize 每页记录数
'p 当前页码
'页面url 如:list.asp?cat=1&p=
Dim PCount, i, Maxi, Mini
If RecordNum Mod PSize = 0 Then
PCount = RecordNum / PSize
Else
PCount = Int(RecordNum / PSize) + 1
End If
If P < 1 Then
P = 1
End If
If CInt(PCount) < 1 Then
PCount = 1
End If
If P > PCount Then P = PCount
Response.Write "共 <b>" & RecordNum & " </b>条记录 每页" & PSize & "条 共" & PCount & "页 当前是第 <b>" & P & "</b> 页 页码: "
Maxi = P + 4
Mini = P - 5
If Maxi > PCount Then Mini = Mini - (Maxi - PCount)
If Mini < 1 Then Maxi = Maxi + (1 - Mini)
If Maxi > PCount Then Maxi = PCount
If Mini < 1 Then Mini = 1
If Mini > 1 Then
Response.Write "<a href=""" & HrefStr & "1"" title=""第1页""><<</a>"
Else
Response.Write "<<"
End If
If P > 10 Then Response.Write " <a href=""" & HrefStr & (P - 10) & """ title=""前10页""> < </a>"
For i = Mini To Maxi
If P = i Then
Response.Write " <b><u>" & i & "</u></b>"
Else
Response.Write " <a href=""" & HrefStr & i & """>" & i & "</a>"
End If
Next
If PCount - P > 10 Then Response.Write " <a href=""" & HrefStr & (P + 10) & """ title=""后10页"">></a>"
If Maxi < PCount Then
Response.Write " <a href=""" & HrefStr & PCount & """ title=""最后1页"">>></a>"
Else
Response.Write " >>"
End If
If PCount > 10 Then Response.Write " <input type=""text"" id=""jumppage"" size=""1"" maxlength=""4"" value=""1""><input type=""button"" value=""GO"" OnClick=""window.location.replace('" & HrefStr & "' + document.getElementById('jumppage').value)"">"
End Sub
/*调用实例*/
Call ShowPageNum(100,10,2,"index.asp?p=")