您现在的位置: 网页制作教程网 >> 网络编程 >> Asp教程 >> ASP 开发技巧 >> 文章正文

ASP网页开发过程中的几个小技巧

作者:网页教学…

来源:网页教学网

热度:

2007-7-9 13:21:49

3.三个文件的主要功能和源程序段:

1)更新.asp

主要功能是让用户输入欲显示的公告,检验输入内容是否为空,若不为空,则提交给”公告.asp”程序处理。

以下为引用的内容:

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<meta name="GENERATOR" content="Microsoft FrontPage 4.0">
<meta name="ProgId" content="FrontPage.Editor.Document">
<title>更新公告栏内容</title>
</head>
<body>
<script language=vbscript>
function datacheck()
dim msg,errflag
errflag=true
     if len(trim(maintain.t1.value))=0 then
           focusto(0)
           errflag=false
           msg="请输入需提交的公告内容"
     end if
     if (errflag=false) then
           msgbox msg,64,"oh no!"     
           exit function
     end if
datacheck=errflag
maintain.submit
end function
sub focusto(x)
     document.maintain.elements(x).focus()
end sub
</script>
①<form method="POST" action="公告.asp" name="maintain">
<p><input type="text" name="t1" size="84"><input type="reset" value="重写" name="B2">
<input type="button" value="提交" name="B1" onclick="datacheck()"></p>


<hr color=#FF99FF size=1>
</form>
</body>
</html>

语句①中的action="公告.asp"部分,指出了在form提交后要启动的程序为“公告.asp”。

2)公告.asp

通过FileSystemObject对象和TextScream对象对"维护文本.txt"文件进行读写操作,使得此文件最上面5行的内容为要在公告栏里显示的公告。

以下为引用的内容:

<%
dim str
str=request.form(t1)
dim s(5)
const forreading=1,forwriting=2
dim fso,myfile
set fso=server.createobject("scripting.FileSystemObject")
set myfile=fso.opentextfile("维护文本.txt",forreading)'以Reading模式打开文件
for i=1 to 5   '公告栏共显示5条公告
     s(i)=myfile.readline'读取文件内容
next
myfile.close
set myfile=fso.opentextfile("维护文本.txt",forwriting,true) '以writing模式打开文件
myfile.writeline str
for i=1 to 4
     myfile.writeline s(i) '将数据写回文件


next
myfile.close
%>

3)维护文本.txt

此文件开始为空,从”更新.asp”显示的界面输入公告后,此文件内容被自动写入。

4.在主页文件(通常是default.asp)欲显示公告位置的代码段中加入如下代码,即可显示出更新后的公告。

以下为引用的内容:

<marquee scrollamount="2" scrolldelay="50" direction="up" width="223" height="133" id="a" onmouseover="a.stop()" onmouseout="a.start()">'公告栏上下滚动
<%
Dim s(20)
Dim fso, MyFile
Set fso = CreateObject("Scripting.FileSystemObject")
Set MyFile = fso.OpenTextFile("D:/ASP/maintain/维护文本.txt",1,true)
for i=1 to 5
ReadLineTextFile=MyFile.ReadLine
s(i)=ReadLineTextFile
response.write "★ " & s(i)
response.write "<br>"


next
%>
</marquee>

上述两个小技巧举一反三,可以解决很多此类问题。网页设计爱好者们不妨一试。

上一页  [1] [2] 


我来说两句:

1分 2分 3分 4分 5分
姓名: *


* 请各位网友遵纪守法并注意语言文明。
网站简介 | 联系方式 | 意见建议 | 版权说明
Copyright © 2007 All rights reserved
滇ICP备06006992号