asp中如何实现长文章自动分页显示
asp中发表的文章太长,有的几千上万字,把页面拉得很长很长,既不美观也不方便浏览,如何实现让超过一定字数的文章自动分页呢...
asp中发表的文章太长,有的几千上万字,把页面拉得很长很长,既不美观也不方便浏览,如何实现让超过一定字数的文章自动分页呢
展开
1个回答
展开全部
<%
dim articleStr,CurrentPage,Maxlen,totalLen,i,j,n
articleStr = rs("content") '从数据库中读取的内容
Maxlen = 1000 '初始化每页显示的字数
totalLen = len(articleStr)
if totalLen mod Maxlen = 0 then
pageCounts = fix(totalLen/Maxlen)
else
pageCounts = fix(totalLen/Maxlen)+1
end if
CurrentPage = Request("page")
if CurrentPage = "" then
CurrentPage = 1
end if
if Clng(CurrentPage) > pageCounts then CurrentPage = pageCounts
i = (CurrentPage-1)*Maxlen+1
j = Maxlen
Response.write mid(articleStr,i,j)&"<br>" '内容显示
'分页代码开始
Response.write "总页数:"&pageCounts&" "
if CurrentPage < 2 then
Response.write "首页 上一页"
else
Response.write "<a href='?id="&request("id")&"&page=1'>首页</a> <a href='?id="&request("id")&"&page="&Cint(CurrentPage)-1&"'>上一页</a>"
end if
if CurrentPage > 3 then Response.write"..."
for n = CurrentPage - 3 to CurrentPage + 3
if n > 0 and Clng(n) <= pageCounts then
Response.write"<a href='?id="&request("id")&"&page="&n&"'>["&n&"]</a> "
end if
next
if CurrentPage + 3 < pageCounts then Response.write"..."
if Clng(CuttentPage) = pageCounts then
Response.write "下一页 末页"
else
Response.write "<a href='?id="&request("id")&"&page="&Cint(CurrentPage)+1&"'>下一页</a> <a href='?id="&request("id")&"&page="&Cint(pageCounts)&"'>末页</a>"
end if
%>
把以上代码保存成某个asp文件,然后在内容页里通过include调用就可以了。具体设置可以自己改,有注释
dim articleStr,CurrentPage,Maxlen,totalLen,i,j,n
articleStr = rs("content") '从数据库中读取的内容
Maxlen = 1000 '初始化每页显示的字数
totalLen = len(articleStr)
if totalLen mod Maxlen = 0 then
pageCounts = fix(totalLen/Maxlen)
else
pageCounts = fix(totalLen/Maxlen)+1
end if
CurrentPage = Request("page")
if CurrentPage = "" then
CurrentPage = 1
end if
if Clng(CurrentPage) > pageCounts then CurrentPage = pageCounts
i = (CurrentPage-1)*Maxlen+1
j = Maxlen
Response.write mid(articleStr,i,j)&"<br>" '内容显示
'分页代码开始
Response.write "总页数:"&pageCounts&" "
if CurrentPage < 2 then
Response.write "首页 上一页"
else
Response.write "<a href='?id="&request("id")&"&page=1'>首页</a> <a href='?id="&request("id")&"&page="&Cint(CurrentPage)-1&"'>上一页</a>"
end if
if CurrentPage > 3 then Response.write"..."
for n = CurrentPage - 3 to CurrentPage + 3
if n > 0 and Clng(n) <= pageCounts then
Response.write"<a href='?id="&request("id")&"&page="&n&"'>["&n&"]</a> "
end if
next
if CurrentPage + 3 < pageCounts then Response.write"..."
if Clng(CuttentPage) = pageCounts then
Response.write "下一页 末页"
else
Response.write "<a href='?id="&request("id")&"&page="&Cint(CurrentPage)+1&"'>下一页</a> <a href='?id="&request("id")&"&page="&Cint(pageCounts)&"'>末页</a>"
end if
%>
把以上代码保存成某个asp文件,然后在内容页里通过include调用就可以了。具体设置可以自己改,有注释
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询
广告 您可能关注的内容 |