用JAVASCRIPT帮我写个计数器
程序员文章站
2023-11-24 09:02:04
你们能用javascript帮我写个计数器吗?要带文本的那种,我在asp那里要用呀?拜托.......... 我...
你们能用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>
我自己写了一个,是不带文本的,谁能帮我弥补一下呢?
<%@ 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>
推荐阅读