(1)建立一个数据库(new.mdb),在这里用ACCESS,加以下字段:
ID 自动编号
dates 日期/时间
comment 备注
title 文本
其中dates字段为更新的时间;comment则为更新内容,如果每条更新内容都很少的话也可以用文本;title则为更新所在的栏目。
(2)建立一个输入FORM,命名为add.htm,内容如下:
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>自动首页更新</title>
<style>
a {text-decoration:none; color:#808000}
a:visited {text-decoration:none; color:#ff0000}
a:hover {color:#E9BB7C; text-decoration:underline}
td {font-size:10.5pt;}
body{font-size:10.5pt;}
</style>
</head>
<body bgcolor="#00FFFF">
<p align="center"><font face="黑体" size="5">更新记录</font><br>
</p>
<form name="nextname" action="add.asp" method="post">
<div align="center"><center><table border="1" width="70%" bordercolor="#cc00FF">
<tr>
<td width="50%">名 字:<input type="text" name="username" size="18" maxlength="10"></td>
<td>密 码:<input type="password" name="userpsd" size="18" maxlength="10"></td>
</tr>
<tr>
<td colspan="2">更新内容:<textarea rows="6" name="comment" cols="54"></textarea></td>
</tr>
<tr>
<td>相关栏目:
<select name="title" size=1><option value="本站站务">本站站务</option>
<option value="goldtimes">goldtimes</option>
<option value="anyshop">anyshop</option></select>
</td>
<td><div align="center"><center><p><input type="submit" value="送出更新内容"></td>
</tr>
</table>
</center></div>
</form>
</body>
</html>
(3)将输入FORM的内容加到数据库,再把最新的十条更新内容生成一个 js 文件。具体程序如下:
<!--#include file="adovbs.inc"-->
<%
username=Request("username")
userpsd =Request("userpsd")
title =Request("title")
comment =Request("comment")
set fso=Server.CreateObject("Scripting.FileSystemObject")
set f=fso.CreateTextFile("c:\inetpub\wwwroot\new.js")
set Conn = Server.CreateObject("ADODB.Recordset")
Conn.Open "new","driver={Microsoft Access Driver (*.mdb)};dbq="&Server.MapPath("new.mdb"),adOpenKeyset,adLockOptimistic
Conn.addnew
Conn("dates")=Date()
Conn("says")=comment
Conn("title")=title
Conn.update
Conn.close
sql="select top 10 * from new order by dates DESC"
Conn.Open sql,"driver={Microsoft Access Driver (*.mdb)};dbq="&Server.MapPath("new.mdb")
f.writeline "m=''"
while NOT Conn.EOF
f.writeline "m+='<font color=blue>"&Conn("dates")&" ["&Conn("title")&"]</font> >>> "&Conn("says")&"<br>';"
Conn.movenext
wend
f.writeline "document.write(m);"
Conn.close
%>
<html>
</head>
</head>
<body>
</body>
</html>
以上已经完成了这个程序的骨干部分,上述代码把您在add.htm里所提交的更新内容保存到new.mdb,自动加上更新日期,并生成new.js,在首页插和代码:
<script language="JavaScript" src="http://YourWebUrl/new.js"></script>
即可。现在需要的是再写个能分页显示所有更新内容的模块。
(4)以下是分页显示所有更新的代码,在首页的最新更新之后加入个链接,具体可看本站首页的源码:
<!--#include file="adovbs.inc"-->
<%
page = Request("page")
if page="" then
page=1
end if
page=CLng(page)
if page<0 or page=0 then
page=1
end if
set news=Server.CreateObject("ADODB.Recordset")
sql="select * from new order by dates DESC"
news.Open sql,"driver={Microsoft Access Driver (*.mdb)};dbq="&Server.MapPath("new.mdb"),AdOpenStatic
news.PageSize=20
news.movefirst
news.AbsolutePage = page
%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>首页更新</title>
<meta name="GENERATOR" content="Microsoft FrontPage 3.0">
<style>
a {text-decoration:none; color:#680068;font-size:9pt;}
a:visited {text-decoration:none; color:#005757;font-size:9pt;}
a:hover {color:#cc0000; text-decoration:underline;}
.sl {font-size:9pt;line-height:14pt}
</style>
</head>
<body>
<div align=center><center>
<table border="0" cellpadding="0" cellspacing="1" width="100%" bgcolor="#008000">
<tr>
<td width="100%"
style="border-left: 1px solid rgb(255,255,255); border-right: 1px solid rgb(0,0,0); border-top: 1px solid rgb(255,255,255); border-bottom: 1px solid rgb(0,0,0)"
bgcolor="#FFFACE" align="center">更新记录</td>
</tr>
<tr>
<td width="100%" bgcolor="#F0F0F0"><p class="sl"><br>
<%
for iPage=1 to news.PageSize
response.write news("dates")&" ["&news("title")&"] >>> "&news("says")&"<br>"
news.MoveNext
If news.EOF Then Exit For
Next
response.write "<p class=sl align=center>"
If page <> 1 Then
Response.Write "<A HREF=allnews.asp?page=1>第一页</A>"
Response.Write "<A HREF=allnews.asp?page=" & (page-1) & ">上一页</A>"
End If
If page <> news.PageCount Then
Response.Write "<A HREF=allnews.asp?page=" & (page+1) & ">下一页</A>"
Response.Write "<A HREF=allnews.asp?page=" & news.PageCount & ">最后一页</A>"
End If
response.write "页数:第 "&page&" 页/共 "&news.PageCount&" 页"
%>
<br><br><a href="JavaScript:window.close();">关闭窗口</a></p></td>
</tr>
</table>
</center></div>
</body>
</html>
更多的ASP文件如何生成JS代码详解请到论坛查看: http://BBS.TC711.COM
【 双击滚屏 】 【 评论 】 【 收藏 】 【 打印 】 【 关闭 】
来源:
互联网
日期:2008-1-27