js读取txt 循环显示

sdd12322 2013-09-17 10:42:00
我不太懂js,只懂点简单的,请各位赐教,我想实现:
通过复选框建立一个txt文件并写入内容,如下
1.html
<html>
<head>
<title> new document </title>
</head>
<SCRIPT LANGUAGE="JavaScript">
<!--
function writeFile(filename,content){
var fso, f, s ;
fso = new ActiveXObject("Scripting.FileSystemObject");
f = fso.OpenTextFile(filename,8,true);
f.WriteLine(content);
f.Close();
}
function writeInfo(name,phone){
var content = "name:"+name+"|phone:"+phone;
writeFile("d:\\info.txt",content);
}
window.onload = function(){

document.getElementById("submit").onclick = function(){
var name = document.getElementById("name").value;
var phone = document.getElementById("phone").value;
writeInfo(name,phone);
alert("写入成功!");
window.location.reload();
}
}
function check(frm){
if (document.form1.named.value=="")

{
alert("请输入姓名");
form1.named.focus();

}
document.getElementById("submit").onclick = function(){
var name = document.getElementById("name").value;
var phone = document.getElementById("phone").value;
writeInfo(name,phone);
alert("写入成功!");
window.location.reload();
}
}
//-->
</SCRIPT>
<body>
<form name="form1">
Name:<input type="text" id="named" name="name"/>
Phone:<input type="text" id="phone" name="phone"/>
<input type="button" id="submit" value="Submit" onclick="return check();">
</form>
</body>
</html>
我想在提交的时候加一个判断,上面运行是可以的,不知道有没有标准的写法。
还有一个就是上面的只能在ie下运行,而在360下不行,请问应该怎么解决呢?
第二个问题是:
对写进txt的内容,我想循环读出来显示在页面上,不知道如何实现。
我现在的页面是这样,如下:
<html>
<head>
<body>
<table width="600" height="400" cellpadding="0" cellspacing="0" border="1" bordercolordark="#000000" id="table" style="font-size:16px; color: #000000;font-weight:bold;" >
<tr>
<td >名字1</td>
<td width="259" >电话1</td>
</tr>

<tr>
<td >名字2</td>
<td width="259" >电话2</td>
</tr>

<tr>
<td >名字3</td>
<td width="259" >电话3</td>
</tr>

.........
//根据txt 文件的内容输出在这里
</table>
</head>
</html>
非常感谢您的解答
...全文
229 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
conanhhy 2013-09-18
  • 打赏
  • 举报
回复
因为用到了ActiveX控件,所以需要设置下安全设置,应该就可以了
浴火_凤凰 2013-09-18
  • 打赏
  • 举报
回复
如果是双击打开运行的话,设置一下360应该可以。 如果是在服务器端运行的话,没有兼容性问题。
fzfei2 2013-09-17
  • 打赏
  • 举报
回复
只能在IE核浏览器上运行,360设置一下应该可以

<html>
<head>
<body>
<table width="600" height="400" cellpadding="0" cellspacing="0" border="1" bordercolordark="#000000" id="table" style="font-size:16px; color: #000000;font-weight:bold;" >
<script>
 function GetALine( )
{
   var fso, f, s;
   s = "";
   fso = new ActiveXObject("Scripting.FileSystemObject");
   f = fso.OpenTextFile('d:\\info.txt', 1, false);
   var ss=[]
   while (!f.AtEndOfStream){
   			ms= f.ReadLine( ).match(/name:([^|]+)\|phone:(.+)/);
   			document.write(
   				'<tr><td >',ms[1] ,'</td><td width="259" >',ms[2],'</td></tr>' 
   			);
   	}
   f.Close( );
}
GetALine();
</script>
</table>
</head>
</html>

87,907

社区成员

发帖
与我相关
我的任务
社区描述
Web 开发 JavaScript
社区管理员
  • JavaScript
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧