ASP 数字分页效果代码
效果:
国外的核心代码:
<%
'digg style pagination script in asp.. written by moazam... http://www.moazam.com/2007/03/30/asp-digg-style-pagination-script/
function getpaginationstring(page, totalitems, limit, adjacents, targetpage)
'defaults
if not isnumeric(adjacents) then adjacents = 1 end if
if not isnumeric(limit) then limit = 15 end if
if not isnumeric(page) then page = 1 end if
if targetpage = "" then targetpage = "/" end if
margin = ""
padding=""
'other vars
prev = page - 1 'previous page is page - 1
nextpage = page + 1 'nextpage page is page + 1
lastpage = ceil(totalitems , limit) 'lastpage is = total items / items per page, rounded up.
lpm1 = lastpage - 1 'last page minus 1
' now we apply our rules and draw the pagination object.
' we're actually saving the code to a variable in case we want to draw it more than once.
pagination = ""
if lastpage > 1 then
pagination = pagination & "<div class=""pagination"""
if margin <> "" or padding <> "" then
pagination = pagination & " style="""
if margin <> "" then
pagination = pagination & "margin: margin"
end if
if padding <> "" then
pagination = pagination & "padding: padding"
end if
pagination = pagination & """"
end if
pagination = pagination & ">"
'previous button
if page > 1 then
pagination = pagination & "<a href="""&targetpage&"&page="&prev&""">prev</a>"
else
pagination = pagination & "<span class=""disabled"">prev</span>"
end if
'pages
if lastpage < 7 + (adjacents * 2) then 'not enough pages to bother breaking it up
for counter = 1 to lastpage
if counter = page then
pagination = pagination & "<span class=""current"">"&counter&"</span>"
else
pagination = pagination & "<a href="""&targetpage&""&"&page="&counter&""">"&counter&"</a>"
end if
next
elseif lastpage >= 7 + (adjacents * 2) then 'enough pages to hide some
'close to beginning only hide later pages
if page < 1 + (adjacents * 3) then
for counter = 1 to (4 + (adjacents * 2))-1
if counter = page then
pagination = pagination & "<span class=""current"">"&counter&"</span>"
else
pagination = pagination & "<a href="""&targetpage&"&page="&counter&""">"&counter&"</a>"
end if
next
pagination = pagination & "..."
pagination = pagination & "<a href="""&targetpage&""&"&page="&lpm1&""">"&lpm1&"</a>"
pagination = pagination & "<a href="""&targetpage&""&"&page="&lastpage&""">"&lastpage&"</a>"
'in middle hide some front and some back
elseif lastpage - (adjacents * 2) > page and page > (adjacents * 2) then
pagination = pagination & "<a href="""&targetpage&"&page=1"">1</a>"
pagination = pagination & "<a href="""&targetpage&"&page=2"">2</a>"
pagination = pagination & "..."
for counter = (page - adjacents) to (page + adjacents)
if counter = page then
pagination = pagination & "<span class=""current"">"&counter&"</span>"
else
pagination = pagination & "<a href="""&targetpage&"&page="&counter&""">"&counter&"</a>"
end if
next
pagination = pagination & "..."
pagination = pagination & "<a href="""&targetpage&"&page="&lpm1&""">"&lpm1&"</a>"
pagination = pagination & "<a href="""&targetpage&"page="&lastpage&""">"&lastpage&"</a>"
'close to end only hide early pages
else
pagination = pagination & "<a href="""&targetpage&"&page=1"">1</a>"
pagination = pagination & "<a href="""&targetpage&"&page=2"">2</a>"
pagination = pagination & "..."
for counter = (lastpage - (1 + (adjacents * 3))) to lastpage
if counter = page then
pagination = pagination & "<span class=""current"">"&counter&"</span>"
else
pagination = pagination & "<a href="""&targetpage&"&page="&counter&""">"&counter&"</a>"
end if
next
end if
end if
'nextpage button
if page < counter - 1 then
pagination = pagination & "<a href="""&targetpage&"&page="&nextpage&""">next</a>"
else
pagination = pagination & "<span class=""disabled"">next</span>"
end if
pagination = pagination & "</div>" & vbnewline
end if
getpaginationstring = pagination
end function
function ceil( dividend, divider)
if (dividend mod divider) = 0 then
ceil = dividend / divider
else
ceil = int(dividend / divider) + 1
end if
end function
'test script code
page = 1
if request("page") <> "" then
page=cint(request("page"))
end if
ps = getpaginationstring(page, 1500, 15, 2, "pagination.asp?foo=bar")
response.write("<br /><br /><br /><br /><br /><br /><br /><br />"&ps)
%>
完整打包代码:
看了有些头晕,还是看点简单的吧,asp与php思想差不多啊,参考了dedecms的修改方法
效果图:
核心代码:
ps=cint(pageno)-2
if ps<1 then
ps=1
end if
pe=clng(pageno)+5
if pe>mpage then pe=mpage
for i=ps to pe
if i=pageno then
lb=lb&"<strong>"&i&"</strong>"
else
lb=lb&"<a href=""/list/list_"&theid&"_"&i&".htm"">"&i&"</a>"
end if
next
完整代码:
pageno=cint(currentpage)
if cint(pageno)>1 then
lb=lb&"<a href=/list/list_"&theid&"_1.htm title=""首页"">首页</a>"
else
lb=lb&"<a href='#'>首页</a>"
end if
if cint(pageno)>1 and cint(pageno) then
lb=lb&"<a href=/list/list_"&theid&"_"&pageno-1&".htm title=""上页"">上页</a>"
else
lb=lb&"<a href='#'>上页</a>"
end if
ps=cint(pageno)-2
if ps<1 then
ps=1
end if
pe=clng(pageno)+5
if pe>mpage then pe=mpage
for i=ps to pe
if i=pageno then
lb=lb&"<strong>"&i&"</strong>"
else
lb=lb&"<a href=""/list/list_"&theid&"_"&i&".htm"">"&i&"</a>"
end if
next
if cint(pageno)<mpage and mpage>1 then
lb=lb&"<a href=/list/list_"&theid&"_"&pageno+1&".htm title=""下页"">下页</a>"
else
lb=lb&"<a href='#'>下页</a>"
end if
if cint(pageno)< mpage then
lb=lb&"<a href=/list/list_"&theid&"_"&mpage&".htm title=""末页"">末页</a>"
end if
上一篇: asp中的Rnd 函数
下一篇: Ajax()方法如何与后台交互