码迷,mamicode.com
首页 > 编程语言 > 详细

JavaScript读写脚txt文件

时间:2016-09-13 22:12:47      阅读:159      评论:0      收藏:0      [点我收藏+]

标签:

1.cmd切换到“C:\Windows\System32>”下,执行“regsvr32 Scrrun.dll”

2.JavaScript读写txt文本代码如下,注意要发布到服务器上

 1 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
 2 <html xmlns="http://www.w3.org/1999/xhtml">
 3 <head>
 4     <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
 5     <title>读写txt文件</title>
 6 </head>
 7 <body>
 8 
 9 <script>
10     function writeFile(filename,filecontent)
11     {
12         var fso, f, s ;
13         fso = new ActiveXObject("Scripting.FileSystemObject");
14         f = fso.OpenTextFile(filename,8,true);
15         f.WriteLine(filecontent);
16         f.Close();
17         alert(‘写入txt数据成功!‘);
18     }
19     //读文件
20     function readFile(filename){
21         var fso = new ActiveXObject("Scripting.FileSystemObject");
22         var f = fso.OpenTextFile(filename,1);
23         var s = "";
24         while (!f.AtEndOfStream)
25             s += f.ReadLine()+"/n";
26         f.Close();
27         return s;
28     }
29 </script>
30 <input type="text" id="txtwrite" value="helloworld">
31 <input type="button" value="Write!" onclick="writeFile(‘c://a.txt‘,document.getElementById(‘txtwrite‘).value)"/>
32 <input type="button" value="Read!" onclick="document.getElementById(‘show‘).value=readFile(‘c:/a.txt‘)"/>
33 <br>
34 <textarea id="show" name="show" cols="30" rows="4" ></textarea>
35 </body>
36 </html>

 

JavaScript读写脚txt文件

标签:

原文地址:http://www.cnblogs.com/lsgwr/p/5869774.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!