三、解決問題
假設(shè)公司新聞頁文件名:news.asp、查詢頁文件名:newslit.asp。
news.asp主要代碼如下:
<html> <head> <meta http-equiv="Content-Type" content="text/html; charset=gb2312" /> <title>公司新聞</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 %>
四、后記
從"動網(wǎng)驗證碼"到"script調(diào)用asp實現(xiàn)過程"再到"Javascript+ASP打造無刷新新聞列表",我們可以舉一反三,例如注冊用戶時無刷新判斷用戶名是否被注冊、無刷新表單驗證等都可以用Javascript+ASP來實現(xiàn)了。
經(jīng)典論壇討論: http://bbs.blueidea.com/thread-2713701-1-1.html
出處:藍(lán)色理想
責(zé)任編輯:blue
上一頁 Javascript+ASP打造無刷新新聞列表 [1] 下一頁
◎進(jìn)入論壇網(wǎng)絡(luò)編程版塊參加討論
|