用ASP写的一个仿Google的翻页控制

原创 2006年02月08日 14:23:00
最近在做一个全文检索时突发奇想,既然大家都习惯了用Google去搜东西,就干脆写一个类似Google的翻页吧,代码如下,使用时只需调用goGoogle()函数即可,样式在一个包含文件中懒的去找了,有兴趣的就自己写吧~~

google-style.asp:
<%
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
'Google-style Page Control
'@by Janylee at 2006.1.6
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''

function goGoogle(countRecord,thisPage,perItems,url)
'params:countRecord - total record count; thisPage - current page number; perItems - items count per page; url: turn to url address(include url params).
 dim totalPageCount
 totalPageCount = (countRecord / perItems) - cInt(countRecord mod perItems <> 0)
 if totalPageCount > 0 then
dim arr,perPageHtml,nextPageHtml
arr = GetMinAndMaxPage(thisPage,totalPageCount)
if thisPage > 1 then
 perPageHtml = "<a href="""& url & GetUrlSign(url) &"page="& thisPage-1 &""" class=""btnper"">上一页</a>"
else
 perPageHtml = "<span class=""btnper"">上一页</span>"
end if
if thisPage < totalPageCount then
 nextPageHtml = "<a href="""& url & GetUrlSign(url) &"page="& thisPage+1 &""" class=""btnnext"">下一页</a>"
else
 nextPageHtml = "<span class=""btnnext"">下一页</span>"
end if
goGoogle = perPageHtml& makeControlItems(arr(0),arr(1),thisPage,url) &nextPageHtml
 else
goGoogle = ""
 end if
end function

function GetMinAndMaxPage(thisPage,totalPageCount)
 dim arr(1)
 if thisPage > 10 then
arr(0) = thisPage - 10
 else
arr(0) = 1
 end if
 if thisPage + 9 < totalPageCount then
   arr(1) = thisPage + 9
 else
   arr(1) = totalPageCount
 end if
 GetMinAndMaxPage = arr
end function

function GetUrlSign(url)
 if inStr(url,"?") <> 0 then
GetUrlSign = "&"
 else
GetUrlSign = "?"
 end if
end function

function makeControlItems(dw,up,nw,url)
 dim i,thisPageStyle,html
 for i = dw to up
if i = nw then
 thisPageStyle = " <span class=""seled"">"& i &"</span> "
else
 thisPageStyle = " <a href="""& url & GetUrlSign(url) &"page="& i &""">"& i &"</a> "
end if
html = html& thisPageStyle
 next
 makeControlItems = html
end function
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
%>
收藏助手
不良信息举报
您举报文章:用ASP写的一个仿Google的翻页控制
举报原因:
原因补充:

(最多只允许输入30个字)