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>
时间: 2024-11-06 03:41:51