本文采用asp和javascript实现无刷新显示文章列表的功能,假设公司新闻页文件名:news.asp、查询页文件名:newslit.asp。
news.asp主要代码如下:
<html>
<head>
<meta http-equiv=”Content-Type” content=”text/html; charset=gb2312″ />
<title>文章列表--IT知道网_</title>
<script language=”JavaScript” type=”text/javascript”>
function showpage(n){
document.scripts[1].src = “newslist.asp?page_no=” + n;
}
</script>
<script language=”JavaScript” type=”text/javascript” src=””></script>
</head>
<body>
<div ID=”titleLiNews”>
</div>
<a href=”javascript:showpage(1);”>1</a>& nbsp;<a href=”javascript:showpage(2);”>2</a>& nbsp;<a href=”javascript:showpage(3);”>3</a>
<script language=”JavaScript” type=”text/javascript”>showpage(1);</script>
</body>
</html>
newslist.asp代码:
<%
Dim conn
Set conn=server.createobject(“ADODB.connection”)
conn.connectionstring=”provider=microsoft.jet.oledb.4.0; data source=” & server.mappath(“db1.mdb”)
conn.open
Dim page_no,sqlstr,rs,i,str
page_no = request.querystring(“page_no”)
Sqlstr = “select * from news”
Set rs = Server.CreateObject(“ADODB.RecordSet”)
Rs.open sqlstr,conn,1,2
Rs.pagesize = 3
Rs.absolutepage = page_no
Str = “document.getElementById(‘titleLiNews’).innerHTML = “”<Ul>”
If rs.eof then str = str & “<li>暂无新闻</li>” & “</Ul>’;”
i = 3
Do while not rs.eof and i > 0
i = i-1
str = str & “<li><a href=’newsview.asp?id=” & rs(“id”) & “‘>” & rs(“title”) & “</a></li>”
rs.movenext
Loop
str = str & “</Ul>””;”
set rs=nothing
set conn = nothing
Response.write str
%>