ASP长文章分页代码实例,也许你会问一篇文章为什么还要进行分页呢?因为文章有短有长,当你的文章很长的时候,如果就一个页面都显示出来的话,读者一看文章这么长,他很可能放弃阅读,他会想这么长我要读到什么时候啊!而且密码麻麻的很容易吓到读者,呵呵!如果你给他分页了,比如1000个文字左右分了一页的话,给读者的心里感觉就不同了,他会不知不觉的阅读下去。
这里使用了文章分页标志:{nextpage}来进行长文章分页,当然你也可以换成其它你喜欢的标志符号,但是一定要注意你的分页标志不能太普通,否则在文章中一旦出现这个标志就会分一页了。
下面我说一下使用分页标志来进行长文章分页的原理,其实分页的原理也很简单,从数据库中读取含有分页标志的文章内容后(当然文章短的话就不用加分页标志了),利用asp的split函数把文章内容存入数组。显示的时候,就按顺序读取数组内容就可以了。
下面的程序基本可以满足动态页面的长文章分页使用了,程序来源网络。
<%
Class aspxsky_page
Private Sub class_initialize
End Sub
Public Function Alert(message,gourl)
message = replace(message,"’","\’")
If gourl="-1" then
Response.Write ("<script language=javascript>alert(’" & message & "’);history.go(-1)</script>")
Else
Response.Write ("<script language=javascript>alert(’" & message & "’);location=’" & gourl &"’</script>")
End If
Response.End()
End Function
Public Sub showpage(str,page,url)
if not isnumeric(page) then
alert "提示:错误的参数!","-1"
end if
if page="" or page=0 or isnull(page) or isempty(page) then
page=1
else
page=cint(page)
end if
str=split(str,"{nextpage}")
abspage=page
pcount=ubound(str)+1
if page>cint(ubound(str)+1) or page<1 then
alert "提示:错误的参数!","-1"
else
response.write str(page-1)&"<br><br><center> 共分为"&pcount&"页 "
end if
for p=0 to ubound(str)
response.write "<a href="&url&"p="&p+1&">["&p+1&"]</a> "
next
response.write "当前第"&abspage&"/"&pcount&"页</center>"
End Sub
End Class
调用方法:这里的str就是文章的内容,在实际使用时换成你文章的内容就可以了。p是页码
p=request.QueryString("p")
str="第一页:这里是第一页的内容{nextpage}第二页:这里是第二页的内容"
url="shownews.asp?id="&id&"&"
set newpage=new aspxsky_page
newpage.showpage str,p,url
当然知道了这个长文章分页的原理后,你完全可以自己试着写个程序,应该不会难的。
| 1、 [move][move][move][fly][fly][fly][fly]d ddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddd[/fly][/fly][/fly][/fly][/move][/move][/move][glow=255,red,2]文字[/glow] 游客 评论于 2008-10-15 |
| 2、 [fly]jfhfghfgh[/fly] 游客 评论于 2008-10-15 |
| 3、 谢谢 太感谢了..解决了我一个大问题呢..谢谢 游客 评论于 2008-11-19 |