我使用以下代码使用
JavaScript创建一个文本文件,它不起作用
<html> <head> <script language="javascript"> function WriteToFile() { var txt = new ActiveXObject("Scripting.FileSystemObject"); var s = txt.CreateTextFile("11.txt",true); s.WriteLine('Hello'); s.Close(); } </script> </head> <body onLoad="WriteToFile()"> </body> </html>
解决方法
试试这个:
<SCRIPT LANGUAGE="JavaScript"> function WriteToFile(passForm) { set fso = CreateObject("Scripting.FileSystemObject"); set s = fso.CreateTextFile("C:\test.txt",True); s.writeline("HI"); s.writeline("Bye"); s.writeline("-----------------------------"); s.Close(); } </SCRIPT> </head> <body> <p>To sign up for the Excel workshop please fill out the form below: </p> <form onSubmit="WriteToFile(this)"> Type your first name: <input type="text" name="FirstName" size="20"> <br>Type your last name: <input type="text" name="LastName" size="20"> <br> <input type="submit" value="submit"> </form>
这只适用于IE