ASP 分页页码翻页上一页下一页通用代码函数漂亮大气

函数

'======================================================================================
'*****参数说明*****
'totalpage总页数
'numperpage每页多少记录
'page当前页码
'pageurl指向URL
'pageindex页码序列数量 0 不显示页码序列
'attachinfo附加参数 如分类 搜索标记和词 等等
'*****Css样式说明*****
'PageDiv 最外层DIV
'a标签页码按钮
'CurrentPage当前页码按钮样式
'Disabled禁用按钮样式
'======================================================================================
Function pagination (totalpage,numperpage,page,pageurl,pageindex,attachinfo)
PageLIstStr=""
AttachInfoStr=attachinfo
PageLIstStr="<div class=""PageDiv"">"
if page>1 then
PageLIstStr=PageLIstStr&"<a href=?page=1&"&AttachInfoStr&">FirstPage</a>&nbsp;"
PageLIstStr=PageLIstStr&"<a href=?page="&(page-1)&AttachInfoStr&">PreviousPage</a>&nbsp;"
else
PageLIstStr=PageLIstStr&"<a class=""Disabled"">FirstPage</a>&nbsp;"
PageLIstStr=PageLIstStr&"<a class=""Disabled"">PreviousPage</a>&nbsp;"
end if

'根据当前页码求FirstPage码和最后页码
if pageindex>0 then
Shows=pageindex
FirstPage=page-round(Shows/2)
if FirstPage<1 then FirstPage=1
LastPage=FirstPage+(Shows-1)
'response.write "FirstPage="&FirstPage
'response.write "LastPage="&LastPage
'response.write "totalpage="&totalpage
if totalpage-LastPage<0 then
'response.write "totalpage-LastPage="&totalpage-LastPage
FirstPage=FirstPage+(totalpage-LastPage)
end if
if LastPage-FirstPage<(Shows-1) then
FirstPage=FirstPage-LastPage-FirstPage
end if
'response.write FirstPage
if FirstPage<1 then FirstPage=1

if FirstPage>1 then
PageLIstStr=PageLIstStr& "<a href=""?page=1&"&AttachInfoStr&""">&nbsp;&nbsp;1&nbsp;&nbsp;</a>&nbsp;...&nbsp;"
else
PageLIstStr=PageLIstStr& "<a class=""Disabled"">&nbsp;&nbsp;1&nbsp;&nbsp;</a>&nbsp;...&nbsp;"
end if

for i=FirstPage to LastPage
if i=page then
PageLIstStr=PageLIstStr& "<a class=""CurrentPage"" href=""?page="&i&AttachInfoStr&""">&nbsp;&nbsp;"&i&"&nbsp;&nbsp;</a>&nbsp;"
else
PageLIstStr=PageLIstStr& "<a href=""?page="&i&AttachInfoStr&""">&nbsp;&nbsp;"&i&"&nbsp;&nbsp;</a>&nbsp;"
end if
if i>=totalpage then exit  for
next

if LastPage<totalpage then
PageLIstStr=PageLIstStr& "...&nbsp;<a href=""?page="&totalpage&AttachInfoStr&""">&nbsp;&nbsp;"&totalpage&"&nbsp;&nbsp;</a>&nbsp;"
else
PageLIstStr=PageLIstStr& "...&nbsp;<a class=""Disabled"">&nbsp;&nbsp;"&totalpage&"&nbsp;&nbsp;</a>&nbsp;"
end if
end if

if page <> totalpage then
PageLIstStr=PageLIstStr&"<a href=""?page="&(page+1)&AttachInfoStr&""">NextPage</a>&nbsp;"
PageLIstStr=PageLIstStr&"<a href=""?page="&totalpage&AttachInfoStr&""">LastPage</a>&nbsp;"
else
PageLIstStr=PageLIstStr&"<a class=""Disabled"">NextPage</a>&nbsp;"
PageLIstStr=PageLIstStr&"<a class=""Disabled"">LastPage</a>&nbsp;"
end if
PageLIstStr=PageLIstStr&"</div>"
pagination=PageLIstStr
End Function

调用

attachinfo="&model=List&searchkey=关键词"
response.write  pagination (totalpage,numperpage,page,pageurl,pageindex,attachinfo)
.PageDiv {
width: 100%;
text-align: center;
font-size: 14px;
margin: 10px;
}
.PageDiv a {
display: inline-block;
background: #ff6600;
padding: 5px 10px;
color: #fff;
text-decoration: none;
border-radius: 2px;
}
.PageDiv a:hover {
background: #0066cc;
}
.PageDiv .CurrentPage {
background: #0066cc;
}
.PageDiv .Disabled {
background: #A7A7A7;
cursor:default;
}
.PageDiv .Disabled:hover {
background: #A7A7A7;
}

展示