现在的位置: 首页 > 综合 > 正文

javascript读写TEXT文本文件示例代码

2013年10月10日 ⁄ 综合 ⁄ 共 1364字 ⁄ 字号 评论关闭

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>pubs</title>
<style>
 table {
  border:2 groove blue;
  position:absolute;
  top:100;
  left:300;
 }
 td {
  border:1 ridge green;
 }
</style>
</head>
<script language="javascript">
 var path="c://";
 var fname="everyone.txt"
 window.status="公告栏";
 function getFname(){
  if (txt1.value != "" && txt1.value != " "){
   fname=txt1.value;
  }
 }
 function savefile(){
  var fso,file;
  if (tbox1.value == ""){
   alert("请输入您想要公告的信息,再存储!");
   return;
  }else{
   getFname();
   fso=new ActiveXObject("Scripting.FileSystemObject");
   file = fso.CreateTextFile(path + fname,true);
   file.WriteLine(tbox1.value);
   file.close();
   alert("完成!");
  }
 }
 function readfile(){
  var fso,str,file;
  getFname();
  fso = new ActiveXObject("Scripting.FileSystemObject");
  str = "没有您的留言";
  if (fso.FileExists(path + fname)){
   file=fso.OpenTextFile(path + fname,1);
   str=file.readall();
   file.close();
  }
  tbox1.value = str;
 }

</script>
<body>
<table width="437" height="157" border="0" align="center" cellpadding="0" cellspacing="0">
  <tr>
    <td width="433" height="28">E-Mail:
      <input type="text" id="txt1">
   <button name="save" onClick="javascript:savefile()">存储</button>
   <button name="read" onClick="javascript:readfile()">阅读</button>
    </td>
  </tr>
  <tr>
    <td height="23"><div align="center">公告内容</div></td>
  </tr>
  <tr>
    <td><textarea name="tbox1" rows="18" cols="60"></textarea></td>
  </tr>
</table>
</body>
</html>

抱歉!评论已关闭.