ASP 数字分页效果代码

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

效果:

国外的核心代码:

代码如下:

<%
 '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(jb51.net).rar

看了有些头晕,还是看点简单的吧,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

(0)

相关推荐

  • ASP 数字分页效果代码

    最近网站改版正好发现原来的分页不带数字的,只有首页 上页 下页 末页 然后是select的跳转,都是以前比较流行的,而现在比较流行的是数字分页在中间,正好研究并分享下,需要的朋友可以参考下 效果: 国外的核心代码: 复制代码 代码如下: <% 'digg style pagination script in asp.. written by Moazam... http://www.moazam.com/2007/03/30/asp-digg-style-pagination-script/ f

  • jquery实现的伪分页效果代码

    本文实例讲述了jquery实现的伪分页效果代码.分享给大家供大家参考,具体如下: 这里介绍的jquery伪分页效果,在火狐下表现完美,IE全系列下有些问题,引入了jQuery1.7.2插件,代码里有丰富的注释,相信对学习jQuery有不小的帮助,期待大家关注. 运行效果截图如下: 在线演示地址如下: http://demo.jb51.net/js/2015/jquery-pic-mn-page-style-codes/ 具体代码如下: <!DOCTYPE html PUBLIC "-//W

  • 非常不错的一个JS分页效果代码,值得研究

    本来想用网上找来的分页程序,不过都得做修改,感觉麻烦了,还是自己写一个好了,以后自己用的时候修改就方便了~~大家都多动手,自己写的才是最好的,日后想干什么的,做修改也是很容易的~~顺便也扩充一下自己的代码库~~ 补充一句,cpage是页面计数,应为全局变量,这样可以随处调用它,totalpage是总页数 JS静态分页程序 a:link,a:visited,a:hover,.current,#info{ border:1px solid #DDD; background:#F2F2F2; disp

  • PHP实现简单数字分页效果

    学习要点: 1.LIMIT 用法 2.各种参数 3.超链接调用 第一:先在文件中设置数字分页模块:我的文件是(blog.php) 复制代码 代码如下: //分页模块 $_page = $_GET['page']; $_pagesize = 10; $_pagenum = ($_page - 1) * $_pagesize; //首页要得到所有的数据总和 $_num=mysql_num_rows(_query("SELECT tg_id FROM tg_user")); $_pageab

  • php仿discuz分页效果代码

    复制代码 代码如下: /** * 显示样式2 */ function multi($mpurl,$page = 10) { $multipage = ''; $mpurl .= strpos($mpurl, '?') ? '&' : '?'; $realpages = 1; if($this->infocount > $this->items) { $offset = 2; $realpages = @ceil($this->infocount / $this->it

  • 网上用的比较多的asp级联菜单效果代码

    复制代码 代码如下: <!--#include file="conn.asp"-->  <html>  <head>  <meta http-equiv="Content-Type" content="text/html; charset=gb2312">  <meta name="GENERATOR" content="Microsoft FrontPage 4

  • Asp.NET 生成静态页面并分页的代码

    1.静态模板页面 template.html,主要是定义了一些特殊字符,用来被替换. 复制代码 代码如下: <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN""http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <meta http-equiv="Content-Type" co

  • Asp.Net 生成静态页并实现分页效果

    1.静态模板页面 template.html,主要是定义了一些特殊字符,用来被替换. 复制代码 代码如下: <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN""http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <meta http-equiv="Content-Type" co

  • asp.net中Datalist使用数字分页的实现方法

    复制代码 代码如下: <%@ Page Language="C#" AutoEventWireup="true" CodeFile="Test(Datalist数字分页).aspx.cs" Inherits="Test_Datalist数字分页_" %> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "

  • 基于vue2.0实现仿百度前端分页效果附实现代码

    前言 上篇文章中,已经使用vue实现前端分页效果,这篇文章我们单独将分页抽离出来实现一个分页组件 先看实现效果图 代码实现 按照惯例,我们在冻手实现的时候还是先想一想vue实现组件的思路 1.需要提前设定哪些参数需要暴露出来给父组件传递 <Paging :name="name" @change="onPageChange" :page-size="size" :total="total" layout="jum

随机推荐