服务器之家:专注于服务器技术及软件下载分享
分类导航

PHP教程|ASP.NET教程|JAVA教程|ASP教程|

ASP 数字分页效果代码

2019-07-04 14:13ASP之家 ASP教程

最近网站改版正好发现原来的分页不带数字的,只有首页 上页 下页 末页 然后是select的跳转,都是以前比较流行的,而现在比较流行的是数字分页在中间,正好研究并分享下,需要的朋友可以参考下

最近网站改版正好发现原来的分页不带数字的,只有首页 上页 下页 末页 然后是select的跳转,都是以前比较流行的,而现在比较流行的是数字分页在中间,正好研究并分享下,需要的朋友可以参考下

效果:

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)
%>



完整打包代码:pagination.rar

 

看了有些头晕,还是看点简单的吧,asp与php思想差不多啊,参考了dedecms的修改方法

效果图:

ASP 数字分页效果代码

核心代码:

 

复制代码代码如下:


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教程asp批量添加修改删除操作示例代码

    asp批量添加修改删除操作示例代码

    这篇文章主要介绍了asp批量添加修改删除操作示例,包括js客户端数据有效性验证,服务器端自己添加验证,需要的朋友可以参考下...

    脚本之家2282019-06-17
  • ASP教程ASP的chr(0)文件上传漏洞原理和解决方法介绍

    ASP的chr(0)文件上传漏洞原理和解决方法介绍

    这篇文章主要介绍了ASP的chr(0)文件上传漏洞原理和解决方法介绍,chr(0)漏洞在上传文件时可以绕过扩展名验证,是一个危害非常大的漏洞,需要的朋友可以参考下...

    服务器之家1422019-07-04
  • ASP教程ASP编码和解码函数详解

    ASP编码和解码函数详解

    用ASP开发的时候遇到一个解码问题。虽然在ASP中使用Request获取编码过URL字符串会自动解码,但是Request.BinaryRead(Request.TotalBytes)取得Post数据时却不会解码,所以只能手动进行解码。 ASP解码函数: Function URLDecode(enStr) dim deStr,strSpecia...

    lijiao1652019-06-23
  • ASP教程asp提示无效使用 Null: Replace

    asp提示无效使用 Null: Replace

    这篇文章主要介绍了asp提示无效使用 Null: Replace,需要的朋友可以参考下...

    服务器之家4282019-06-29
  • ASP教程asp中使用MSXML2.DOMDocument处理XML数据时的注意事项

    asp中使用MSXML2.DOMDocument处理XML数据时的注意事项

    这篇文章主要介绍了asp中使用MSXML2.DOMDocument处理XML数据时的注意事项,本文给出了4个需要注意的问题,需要的朋友可以参考下...

    junjie2602019-06-30
  • ASP教程ASP网站中数据库被挂木马的解决方案

    ASP网站中数据库被挂木马的解决方案

    我们在用ASP连接数据库开发应用程序时,可能会遇到ASP数据库被挂木马的情况,本文我们就介绍了ASP数据库被挂木马时的编程处理方法,希望会对您有所帮助...

    小路4342019-06-26
  • ASP教程ASP 数字分页效果代码

    ASP 数字分页效果代码

    最近网站改版正好发现原来的分页不带数字的,只有首页 上页 下页 末页 然后是select的跳转,都是以前比较流行的,而现在比较流行的是数字分页在中间,正好研究并分享下,需要的朋友可以参考下...

    ASP之家3122019-07-04
  • ASP教程ASP中限制某些字符留言评论

    ASP中限制某些字符留言评论

    这篇文章主要介绍了ASP中限制某些字符留言评论,原理就是通过instr函数查找。感觉很简单,写起来还是有点手生,感觉阿会南...

    服务器之家1352019-07-04