注册 登录
编程论坛 ASP技术论坛

【求助】按钮事件触发写文件失败

cyhcqcys 发布于 2010-04-08 09:38, 681 次点击
正在做毕设,想通过触发按钮事件,写入本地磁盘的txt文件。但触发后无响应(本地磁盘没有生成相应txt)。请问是什么问题?
代码如下:
<html>
<head>
<title>测试按钮事件</title>
</head>
<body>
<input type="button" name="button1" value="up">
<script for="button1" event="onclick" language="vbscript">
  Set MyFileObject=Server.CreateObject("Scripting.FileSystemObject")
  Set MyTextFile=MyFileObject.CreateTextFile("c:\test.txt")
  MyTextFile.WriteLine("up")
  MytextFile.Close
</script>
</body>
</html>
4 回复
#2
gupiao1752010-04-08 16:13
正在做毕设,想通过触发按钮事件,写入本地磁盘的txt文件。但触发后无响应(本地磁盘没有生成相应txt)。请问是什么问题?
代码如下:
<html>
<head>
<title>测试按钮事件</title>
</head>
<body>
<input type="button" name="button1" value="up">
<script for="button1" event="onclick" language="vbscript">
  Set MyFileObject=Server.CreateObject("Scripting.FileSystemObject")
  Set MyTextFile=MyFileObject.CreateTextFile("c:\test.txt")
  MyTextFile.WriteLine("up")
  MytextFile.Close
</script>
</body>
</html>
把Server.删除掉,因为是客户端执行VBSCRIPT,加SERVER。会提示脚本缺少对象!
#3
nicechlk2010-04-11 13:49
dim path
path=server.MapPath(c:\)   '生成绝对路径
#4
yms1232010-04-11 18:04
此操作肯定会被浏览器或杀毒软件拦截的。
#5
zzy_4202010-04-11 21:48
Server是 ASP 对象,不能放在脚本中。


正在做毕设,想通过触发按钮事件,写入本地磁盘的txt文件。但触发后无响应(本地磁盘没有生成相应txt)。请问是什么问题?
代码如下:
<html>
<head>
<title>测试按钮事件</title>
</head>
<body>
<input type="button" name="button1" value="up">
<script for="button1" event="onclick" language="vbscript">
  Set MyFileObject=Server.CreateObject("Scripting.FileSystemObject")
  Set MyTextFile=MyFileObject.CreateTextFile("c:\test.txt")
  MyTextFile.WriteLine("up")
  MytextFile.Close
</script>
</body>
</html>

把上面红色代码换成下面代码就可以了

正在做毕设,想通过触发按钮事件,写入本地磁盘的txt文件。但触发后无响应(本地磁盘没有生成相应txt)。请问是什么问题?
代码如下:
<html>
<head>
<title>测试按钮事件</title>
</head>
<body>
<input type="button" name="button1" value="up">
<script for="button1" event="onclick" language="javascript">
  var MyFileObject=new ActiveXObject("Scripting.FileSystemObject")
  var MyTextFile=MyFileObject.CreateTextFile("c:\test.txt")
  MyTextFile.WriteLine("up")
  MytextFile.Close
</script>
</body>
</html>

[ 本帖最后由 zzy_420 于 2010-4-11 21:58 编辑 ]
1