论坛: 网站建设 标题: ASP翻页样式处理函数[仿动网和leadbbs] 复制本贴地址    
作者: NetFog [q70213526]    版主   登录
演示: http://www.xitour.com/Lab/Links/demoPage.asp

如果觉得下面代码不太清楚. http://www.xitour.com/bbs/a/a.asp?BoardID=5&ID=167&Aupflag=1&Anum=1 这里的可能更清楚点..

心得:
在ASP常用的脚本VBScript中,具有四舍五入功能的Cint、Round函数存在点小小BUG。对类似2.5,4.5这样的数字使用Cint、Round函数时。得到的值分另为2和4,而类似1.5和3.5都会真正四舍五入。。

规律:当小数点前的第一个数字为偶数,且小数点后只有一位5时,Cint,Rounc函数不能四舍五入。

为了实现我的翻页样式函数,特别自己写了个四舍五入函数。嘿嘿。翻面页程序代码如下:

PS:注释没写了.我已经懒到家了..如果有人要用这个函数的.有问题再问我.
另外,代码中的前一部分有CSS的.函数一共两个.一个四舍五入函数和一个主体函数.
代码:

<style type="text/css">
<!--
a:link {
font-family: "宋体";
color: #000000;
text-decoration: none;
}
a:visited {
font-family: "宋体";
font-size: 12px;
color: #999999;
text-decoration: none;
}
a:hover {
font-family: "宋体";
font-size: 13px;
color: #33CC00;
text-decoration: none;
}
td {
font-family: Arial, Helvetica, sans-serif;
font-size: 12px;
color: #000000;
}
body {
font-family: Arial, Helvetica, sans-serif;
font-size: 12px;
}
-->
</style>

<%
''===============================================
''@name            getPageLink
''@date            2005-8-23
''@author          NetFog
''@desc            翻页样式
''===============================================

Dim demoResult,CurPage,TotalPage,Step
CurPage = Request("Page")
TotalPage = 50
Step = 9

If (CurPage = "") Or (IsNumeric(CurPage) = False) or (CurPage < 1) Then
CurPage = 1
End If

CurPage = Cint(CurPage)

If CurPage > TotalPage Then CurPage = TotalPage

demoResult = getPageLink(CurPage,TotalPage,Step,"Page","demoPage.asp","&OtherParameter=15","<td width=20 valign=middle height=18 align=center bgcolor=""#FFFFFF"">","</td>","<td width=20 valign=middle height=18 align=center bgcolor=red>","</td>","<font face=webdings title=首页>9</font>","<font face=webdings title=尾页>:</font>","<font face=webdings title=上页>7</font>","<font face=webdings title=下页>8</font>")

Response.Write "<table border=0 cellspacing=1 bgcolor=#000000><tr>" & demoResult & "</tr></table>"

Function getPageLink(pCurPage,pTotalPage,pStep,pPageParameter,pURL,pOtherParameter,pUrlHead,pUrlFoot,pCurUrlHead,pCurUrlFoot,pFirstPageStr,pLastPageStr,pPrePageStr,pNextPageStr)
Dim TmpResult,MiddleNumber,HasPrePage,HasNextPage,i,LinksHead,LinksFoot,OtherInfo
MiddleNumber = FormatInt(pStep/2)
TmpResult = ""
HasPrePage = 0
HasNextPage = 0
LinksHead = ""
LinksFoot = ""
If pTotalPage <= pStep Then
For i = 1 to pTotalPage
If i = pCurPage Then
TmpResult = TmpResult & pCurUrlHead & i & pCurUrlFoot
Else
TmpResult = TmpResult & pUrlHead & "<a href=" & pURL & "?" & pPageParameter & "=" & i & pOtherParameter & ">" & i & "</a>" & pUrlFoot
End If
Next
End If
If pTotalPage > pStep Then
If pCurPage<=MiddleNumber Then
For i = 1 to pCurPage
If i = pCurPage Then
TmpResult = TmpResult & pCurUrlHead & i & pCurUrlFoot
Else
TmpResult = TmpResult & pUrlHead & "<a href=" & pURL & "?" & pPageParameter & "=" & i & pOtherParameter & ">" & i & "</a>" & pUrlFoot
End If
Next
For i = pCurPage+1 To pStep
TmpResult = TmpResult & pUrlHead & "<a href=" & pURL & "?" & pPageParameter & "=" & i & pOtherParameter & ">" & i & "</a>" & pUrlFoot
Next
ElseIf pCurPage>MiddleNumber Then
For i = pCurPage-MiddleNumber+1 To pCurPage
If i = pCurPage Then
TmpResult = TmpResult & pCurUrlHead & i & pCurUrlFoot
Else
TmpResult = TmpResult & pUrlHead & "<a href=" & pURL & "?" & pPageParameter & "=" & i & pOtherParameter & ">" & i & "</a>" & pUrlFoot
End If
Next
If pCurPage+pStep-MiddleNumber < pTotalPage Then
For i = pCurPage + 1 To pCurPage+pStep-MiddleNumber
TmpResult = TmpResult & pUrlHead & "<a href=" & pURL & "?" & pPageParameter & "=" & i & pOtherParameter & ">" & i & "</a>" & pUrlFoot
Next
Else
For i = pCurPage + 1 To pTotalPage
TmpResult = TmpResult & pUrlHead & "<a href=" & pURL & "?" & pPageParameter & "=" & i & pOtherParameter & ">" & i & "</a>" & pUrlFoot
Next
End If
End If
End If
If pCurPage > 1 Then HasPrePage = 1
iF pCurPage < pTotalPage Then HasNextPage = 1
If HasPrePage = 1 Then
LinksHead = LinksHead & pUrlHead & "<a href=" & pURL & "?" & pPageParameter & "=1" & pOtherParameter & ">" & pFirstPageStr & "</a>" & pUrlFoot & pUrlHead & "<a href=" & pURL & "?" & pPageParameter & "=" & pCurPage-1 & pOtherParameter & ">" & pPrePageStr & "</a>" & pUrlFoot
Else
LinksHead = LinksHead & pUrlHead & pFirstPageStr & pUrlFoot & pUrlHead & pPrePageStr & pUrlFoot
End If
If HasNextPage = 1 Then
LinksFoot = LinksFoot & pUrlHead & "<a href=" & pURL & "?" & pPageParameter & "=" & pCurPage+1 & pOtherParameter & ">" & pNextPageStr & "</a>" & pUrlFoot & pUrlHead & "<a href=" & pURL & "?" & pPageParameter & "=" & pTotalPage & pOtherParameter & ">" & pLastPageStr & "</a>" & pUrlFoot
Else
LinksFoot = LinksFoot & pUrlHead & pNextPageStr & pUrlFoot & pUrlHead & pLastPageStr & pUrlFoot
End If
TmpResult = LinksHead & TmpResult & LinksFoot
getPageLink = TmpResult
End Function

Function FormatInt(vInt)
Dim TempStrLeft,TempStrRight,DotPos,TempStrInt
TempStrInt = Cstr(vInt)
DotPos = InStr(TempStrInt,".")
If DotPos = 0 Then FormatInt = vInt : Exit Function
TempStrLeft = FormatNumber(Left(TempStrInt,DotPos-1),0)
TempStrRight = FormatNumber("0." & Right(TempStrInt,Len(TempStrInt)-DotPos),6)
If TempStrRight>=0.5 Then
FormatInt = TempStrLeft + 1
Else
FormatInt = TempStrLeft
End If
End Function
%>



[此贴被 NetFog(q70213526) 在 08月24日13时26分 编辑过]

地主 发表时间: 06-08-24 13:19

论坛: 网站建设

20CN网络安全小组版权所有
Copyright © 2000-2010 20CN Security Group. All Rights Reserved.
论坛程序编写:NetDemon

粤ICP备05087286号