<html>
<head>
<script language="javascript11">
var count=1;
function addTextFile()
{
var fso1, f11, ts1, s1;
var ForReading = 1;
// 打開檔案
fso1 = new ActiveXObject("Scripting.FileSystemObject");
ts1 = fso1.OpenTextFile("c:\\test.txt", ForReading);
// 讀取檔案一行內容到字元串
s1 = ts1.ReadLine();
alert(s1);
// 顯示字元串信息
var show=document.getElementById("show");
show.innerHTML=s1;
// 關閉檔案
ts1.Close();
var fso, ts, s;
var ForWriting= 2;
fso = new ActiveXObject("Scripting.FileSystemObject");
ts = fso.OpenTextFile("c:\\test.txt", ForWriting, true);
var name=document.getElementById("name").value;
alert(name);
s = s1;
alert(s);
alert("test");
s = s + count+"="+escape(name)+"; ";
alert(s);
ts.WriteLine(s) ;
count=count+1;
ts.Close();
}
function getOldText()
{
var fso1, f11, ts1, s1;
var ForReading = 1;
// 打開檔案
fso1 = new ActiveXObject("Scripting.FileSystemObject");
ts1 = fso1.OpenTextFile("c:\\test.txt", ForReading);
// 讀取檔案一行內容到字元串
s1 = ts1.ReadLine();
alert(s1);
// 顯示字元串信息
var show=document.getElementById("show");
show.innerHTML=s1;
// 關閉檔案
ts1.Close();
return s1;
}
function displayTextFile()
{
var fso, f1, ts, s;
var ForReading = 1;
// 打開檔案
fso = new ActiveXObject("Scripting.FileSystemObject");
ts = fso.OpenTextFile("c:\\test.txt", ForReading);
// 讀取檔案一行內容到字元串
s = ts.ReadAll();
// 顯示字元串信息
var show=document.getElementById("show");
show.innerHTML=s;
// 關閉檔案
ts.Close();
}
</script>
</head>
<body>
<input type="text" id="name">
<input type="button" onclick="addTextFile()" value="添加檔案">
<input type="button" onclick="displayTextFile()" value="顯示檔案">
<div id="show"></div>
</body>
</html>