之前在做网站的时候,总想实现类似像Discuz的分页效果,在网上找了很长时间都没找到,前几天在网上偶然发现这个效果的Asp版本的,还是收藏一下。
先看效果演示:
程序代码如下:
程序代码
里边的样式来自Discuz,下边就是样式列表
程序代码
调用方法:
程序代码
先看效果演示:

程序代码如下:

' 目的:分页
' 参数:Totles:总记录;Perpage:每页显示记录;Curpage:当前页;URL:分页连接;
' 返回:分页后的字符串
' 作者:长江
' 时间:2007-9-25
Function MultiPage(Totles,Perpage,Curpage,URL)
Dim i,fromPage,toPage,pages
Totles=Int(Totles)
Perpage=Int(Perpage)
Curpage=Int(Curpage)
URL=Request.ServerVariables("Script_Name")&URL
If Totles Mod Cint(Perpage)=0 Then
pages=Int(Totles/Perpage)
Else
pages=Int(Totles/Perpage)+1
End If
MultiPage="<div class=""p_bar""><a class=""p_total""> "&Totles&" </a><a class=""p_pages""> "&Curpage&"/"&Pages&" </a>"
If pages>10 And Curpage>3 Then MultiPage=MultiPage&"<a href="&URL&"1 class=""p_redirect"">|‹</a>"
If Curpage<>1 Then MultiPage=MultiPage&"<a href="&URL&Curpage-1&" class=""p_redirect"">‹‹</a>"
If pages<=10 Then
fromPage=1
toPage=pages
Else
If Curpage<=3 And pages-Curpage>=8 Then
fromPage=1
toPage=10
ElseIf Curpage>3 And pages-Curpage<8 Then
fromPage=pages-9
toPage=pages
Else
fromPage=Curpage-2
toPage=Curpage+7
End If
End If
For i=fromPage To toPage
If i<>Curpage Then
MultiPage=MultiPage&"<a href="&URL&i&" class=""p_num"""&i&">"&i&"</a>"
Else
MultiPage=MultiPage&"<a href="&URL&i&" class=""p_curpage"""&i&">"&i&"</a>"
End If
Next
If Curpage<>pages Then MultiPage=MultiPage&"<a href="&URL&Curpage+1&" class=""p_redirect"">››</a>"
If pages>10 And pages-Curpage>3 Then MultiPage=MultiPage&"<a href="&URL&pages&" class=""p_redirect"">›|</a>"
If pages>10 Then MultiPage=MultiPage&"<a class=""p_pages"" style=""padding: 0px""><input class=""p_input"" type=""text"" name=""page"" onKeyDown=""if(event.keyCode==13) {window.location='"&URL&"'+this.value; return false;}""></a>"
MultiPage=MultiPage&"</div>"
End Function
' 参数:Totles:总记录;Perpage:每页显示记录;Curpage:当前页;URL:分页连接;
' 返回:分页后的字符串
' 作者:长江
' 时间:2007-9-25
Function MultiPage(Totles,Perpage,Curpage,URL)
Dim i,fromPage,toPage,pages
Totles=Int(Totles)
Perpage=Int(Perpage)
Curpage=Int(Curpage)
URL=Request.ServerVariables("Script_Name")&URL
If Totles Mod Cint(Perpage)=0 Then
pages=Int(Totles/Perpage)
Else
pages=Int(Totles/Perpage)+1
End If
MultiPage="<div class=""p_bar""><a class=""p_total""> "&Totles&" </a><a class=""p_pages""> "&Curpage&"/"&Pages&" </a>"
If pages>10 And Curpage>3 Then MultiPage=MultiPage&"<a href="&URL&"1 class=""p_redirect"">|‹</a>"
If Curpage<>1 Then MultiPage=MultiPage&"<a href="&URL&Curpage-1&" class=""p_redirect"">‹‹</a>"
If pages<=10 Then
fromPage=1
toPage=pages
Else
If Curpage<=3 And pages-Curpage>=8 Then
fromPage=1
toPage=10
ElseIf Curpage>3 And pages-Curpage<8 Then
fromPage=pages-9
toPage=pages
Else
fromPage=Curpage-2
toPage=Curpage+7
End If
End If
For i=fromPage To toPage
If i<>Curpage Then
MultiPage=MultiPage&"<a href="&URL&i&" class=""p_num"""&i&">"&i&"</a>"
Else
MultiPage=MultiPage&"<a href="&URL&i&" class=""p_curpage"""&i&">"&i&"</a>"
End If
Next
If Curpage<>pages Then MultiPage=MultiPage&"<a href="&URL&Curpage+1&" class=""p_redirect"">››</a>"
If pages>10 And pages-Curpage>3 Then MultiPage=MultiPage&"<a href="&URL&pages&" class=""p_redirect"">›|</a>"
If pages>10 Then MultiPage=MultiPage&"<a class=""p_pages"" style=""padding: 0px""><input class=""p_input"" type=""text"" name=""page"" onKeyDown=""if(event.keyCode==13) {window.location='"&URL&"'+this.value; return false;}""></a>"
MultiPage=MultiPage&"</div>"
End Function
里边的样式来自Discuz,下边就是样式列表

/* ==========page分页=========== */
.p_bar {
margin: 1px 0px;
clear: both;
width: 100%;
height: 22px;
padding-top: 3px;
padding-bottom: 1px !important;
}
.p_bar a {
float: left;
padding: 1px 4px;
font-size: 12px;
text-decoration: none;
}
.p_input {
border: 0px;
padding: 0px;
width: 40px;
height: 18px !important;
> height: 15px !important;
height: 15px;
margin: 0px;
background: #FFFFFF;
}
.p_total {
background-color: #F5FBFF;
border: 1px solid #6699CC;
border-right: 0px solid #6699CC;
font-weight: bold;
}
.p_pages {
background-color: #F5FBFF;
border: 1px solid #6699CC;
margin-right:1px;
vertical-align: middle;
font-weight: bold;
}
.p_num {
background-color: #FFFFFF;
border: 1px solid #A3C2E0;
margin-right:1px;
vertical-align: middle;
}
a:hover.p_num {
background-color: #F5FBFF;
border: 1px solid #6699CC;
text-decoration: none;
}
.p_redirect {
background-color: #FFFFFF;
border: 1px solid #A3C2E0;
margin-right:1px;
font-size: 12px !important;
font-size: 13px;
}
a:hover.p_redirect {
background-color: #F5FBFF;
border: 1px solid #0099FF;
text-decoration: none;
}
.p_curpage {
margin-right:1px;
border: 1px solid #A3C2E0;
vertical-align: middle;
background-color: #FBFFE1;
color: #FF6600;
font-weight: bold;
}
.p_bar {
margin: 1px 0px;
clear: both;
width: 100%;
height: 22px;
padding-top: 3px;
padding-bottom: 1px !important;
}
.p_bar a {
float: left;
padding: 1px 4px;
font-size: 12px;
text-decoration: none;
}
.p_input {
border: 0px;
padding: 0px;
width: 40px;
height: 18px !important;
> height: 15px !important;
height: 15px;
margin: 0px;
background: #FFFFFF;
}
.p_total {
background-color: #F5FBFF;
border: 1px solid #6699CC;
border-right: 0px solid #6699CC;
font-weight: bold;
}
.p_pages {
background-color: #F5FBFF;
border: 1px solid #6699CC;
margin-right:1px;
vertical-align: middle;
font-weight: bold;
}
.p_num {
background-color: #FFFFFF;
border: 1px solid #A3C2E0;
margin-right:1px;
vertical-align: middle;
}
a:hover.p_num {
background-color: #F5FBFF;
border: 1px solid #6699CC;
text-decoration: none;
}
.p_redirect {
background-color: #FFFFFF;
border: 1px solid #A3C2E0;
margin-right:1px;
font-size: 12px !important;
font-size: 13px;
}
a:hover.p_redirect {
background-color: #F5FBFF;
border: 1px solid #0099FF;
text-decoration: none;
}
.p_curpage {
margin-right:1px;
border: 1px solid #A3C2E0;
vertical-align: middle;
background-color: #FBFFE1;
color: #FF6600;
font-weight: bold;
}
调用方法:

<%
Dim curpage,perpage
curpage=Request.QueryString("page")
perpage=10
Set Rs=Server.CreateObject("ADODB.Recordset")
SQL="Select * FROM [Table]"
Rs.Open SQL,Conn,1,1
If Not Rs.Eof Then
Rs.PageSize=Perpage
Rs.AbsolutePage=curpage
Dim totle
totle=Rs.RecordCount
Response.Write MultiPage(totle,perpage,curpage,"?page=")'想要分页信息显示在记录下边,把这句放下边即可
End If
Do Until Rs.EOF
%>
需要显示的记录
<%
Rs.MoveNext
Loop
%>
Dim curpage,perpage
curpage=Request.QueryString("page")
perpage=10
Set Rs=Server.CreateObject("ADODB.Recordset")
SQL="Select * FROM [Table]"
Rs.Open SQL,Conn,1,1
If Not Rs.Eof Then
Rs.PageSize=Perpage
Rs.AbsolutePage=curpage
Dim totle
totle=Rs.RecordCount
Response.Write MultiPage(totle,perpage,curpage,"?page=")'想要分页信息显示在记录下边,把这句放下边即可
End If
Do Until Rs.EOF
%>
需要显示的记录
<%
Rs.MoveNext
Loop
%>