你們能用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>