首页 > 编程 > ASP > 正文

ASP中利用 Jauery 实现AJAX分页效果

2024-05-04 11:07:17
字体:
来源:转载
供稿:网友

准备工作 Jquery-man.js

需要分页地方

<script language="javascript">
function CheckPage(pages){
$("#plShow").load("plAjax.asp?ID=<%=news_id%>&p="+pages);
}
</script>

<div id="plShow">
 <script language="javascript">
    $("#plShow").load("plAjax.asp?ID=<%=news_id%>");
 </script>
</div>
<%

'完了,就是这么简单 ...

%>

plAjax.asp 显示分页

<!--#include file="inc/conn.asp"-->
<%
   ID = request.QueryString("ID")
   if ID = "" or isnull("ID") then
      response.End()
   end if
   P = request.QueryString("p")
   if P = "" or isnull("P") then
      P = 1
   end if
   if P = 1 then
      sql = "select top 5 * from pl where byID='"&ID&"' order by id desc"
   else
   pz = 5*(P-1)
      sql = "select top 5 * from pl where id not in(select top "&pz&" id from pl where byID='"&ID&"' order by id desc) and byID='"&ID&"' order by id desc"
   end if
   response.Charset="gb2312"
   set rs = conn.execute(sql)
   if rs.eof then
      response.Write "<dl><dt style='color:#FF0000'>暂无评论!</dt></dl>"
   response.End()
   end if
   while not rs.eof
%>
<dl>
   <dt><img src="Image/page/face/<%=rs("face")%>.png" />&nbsp;
   <%
      if rs("isShow") then
      response.Write "游客"
   else
      response.Write rs("name")
   end if
   %>
   &nbsp;<%=rs("adddate")%> 发表
   </dt>
   <dt><%=rs("content")%></dt>
</dl>
<%
   rs.movenext
   wend
   rs.close
%>
<div style="height:40px;">

   <ul class="Page" style="margin-top:20px;">
<%

'这里采用了仿百度分页效果
sql = "select count(*) as maxnum from pl where byID='"&ID&"'"
rs = conn.execute(sql)
maxnum = rs("maxnum")
if maxnum mod 5 then
   pageCount = int(maxnum/5)+1
else
   pageCount = maxnum/5
end if
if P = 1 or P<1 then
   response.Write "<li>首页</li><li>上页</li>"
else
   response.Write "<li><a href='javascript:void(0);' onclick='CheckPage(1)'>首页</a></li><li><a href='javascript:void(0);' onclick='CheckPage("&P-1&")'>上页</a></li>"
end if
if P>1 then a=1
if P>2 then a=2
if P>3 then a=3
if P>4 then a=4
if P>5 then a=4
for i=(P-a) to P-1
   response.Write "<li class='dpage'><a href='javascript:void(0);' onclick='CheckPage("&i&")'>"&i&"</a></li>"
next
response.Write  "<li>"&P&"</li>"
for j=(P+1) to (P+5)
   if j>pageCount then
      exit for
   end if
   response.Write "<li class='dpage'><a href='javascript:void(0);' onclick='CheckPage("&j&")'>"&j&"</a></li>"
next
if int(P) = int(pageCount) or int(pageCount) = 0 then
   response.Write "<li>下页</li><li>尾页</li>"
else
   response.Write "<li><a href='javascript:void(0);' onclick='CheckPage("&P+1&")'>下页</a></li><li><a href='javascript:void(0);' onclick='CheckPage("&pageCount&")'>尾页</a></li>"
end if
%> 
   </ul>
</div>

 
' 样式表

.Page{
  width:auto; height:16px;
}
.Page li{
  display:inline; height:16px; line-height:16px; padding-left:6px; text-align:center; margin-left:5px; padding-right:5px
}
.Page .dpage{
 border:1px #D6D6D6 solid; background:#F7F7F7; font-weight:bold;
}

#plShow dl{
  height:auto; border-bottom:1px #D6D6D6 dashed; margin-top:8px; clear:both; width:95%;
}
#plShow dt{
  height:24px; text-align:left; line-height:24px; color:#666;
}

发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表