用JAVASCRIPT幫我寫個計數器

來源:互聯網
上載者:User

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

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.