你們能用JAVASCRIPT幫我寫個計數器嗎?要帶文本的那種,我在ASP那裡要用呀?拜托..........
我自己寫了一個,是不帶文本的,誰能幫我彌補一下呢?
<%@ Language=Jscript %>
<%
Application.Lock();
Application("Counter") = parseInt(Application("Counter")) + 1;
Application.UnLock();
%>
我知道要用到<%
var path = Server.MapPath("test.txt");
var MyFileObject = Server.CreateObject("Scripting.FileSystemObject");
var MyTextFile = MyFileObject.CreateTextFile(path);
MyTextFile.WriteLine("");
MyTextFile.Close();
%>這些命令,可具體怎麼寫呢?
復制代碼 代碼如下:
給你一個最全的吧:
<script language = "vbscript" runat = "server">
sub application_onstart
'取的計數文件的真實路徑
countfile=server.mappath("count.txt")
'創建文件系統對象實例
set myfso = server.createobject("scripting.filesystemobject")
'若計數文件不存在
if not myfso.fileexists(countfile) then
'創建該文件及取得textstream對象實例
set mytextstream = myfso.createtextfile(countfile, True)
application.lock
application("online") = 0
application("counter") = 0
application.unlock
'將計數值寫入文件
mytextstream.writeline(cstr(application("counter")))
else
'以只讀的方式打開
set mytextstream = myfso.opentextfile(countfile,1,false)
'讀一行,並將值賦給計數變量
application("counter") = mytextstream.readline
end if
mytextstream.close
set myfso = nothing
end sub
sub session_onstart
session.timeout = 1
countfile = server.mappath("count.txt")
set myfso = server.createobject("scripting.filesystemobject")
application.lock
application("online") = application("online")+1
application("counter") = application("counter")+1
application.unlock
'以寫方式打開文件
set mytextstream = myfso.opentextfile(countfile,2,false)
'以寫行的方式將數據寫入文件
mytextstream.writeline(cstr(application("counter")))
mytextstream.close
set myfso = nothing
end sub
sub session_onend
application.lock
application("online") = application("online")-1
application.unlock
end sub
</script>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>計數器例子</title>
</head>
<body>
<div align="center">您是本站第<font color="#FF0000"><%=application("counter")%></font>位貴賓!
</div>
</body>
</html>