js读取txt 循环显示
我不太懂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>
非常感谢您的解答