我试图将textarea的输入保存到.txt文件。
另一个textarea将用于文件名
(例如:重要 - 它将important.txt
保存在所选目录中)
到目前为止我得到了什么:
<html>
<head>
<script language="javascript">
function WriteToFile()
{
var fso = new ActiveXObject("Scripting.FileSystemObject");
var s = fso.CreateTextFile("C:\inetpub\wwwroot\myfile.txt", true);
var text=document.getElementById("TextArea1").innerText;
s.WriteLine(text);
s.WriteLine('***********************');
s.Close();
}
</script>
</head>
<body>
<form>
<div>
<textarea id="TextArea1" height: style="width: 588px; height: 90px" 90px">Write here</textarea><br />
<input id="Button1" type="button" value="Write" onclick="WriteToFile()"/>
</div>
</form>
</body>
</html>
答案 0 :(得分:0)
这样的东西?
<html>
<head>
<script language="javascript">
function WriteToFile()
{
var fso = new ActiveXObject("Scripting.FileSystemObject");
var text=document.getElementById("TextArea1").innerText;
var fileName=document.getElementById("TextArea2").innerText;
var s = fso.CreateTextFile("C:\\inetpub\\wwwroot\\"+fileName+".txt", true);
s.WriteLine(text);
s.WriteLine('***********************');
s.Close();
}
</script>
</head>
<body>
<form>
<div>
<textarea id="TextArea1" height: style="width: 588px; height: 90px" 90px">Write here</textarea><br />
<textarea id="TextArea2" height: style="width: 588px; height: 90px" 90px">Type File name</textarea>
<input id="Button1" type="button" value="Write" onclick="WriteToFile()"/>
</div>
</form>
</body>
</html>
BTW我认为ActiveXObject只能在IE浏览器中使用 查看ActiveXObject in Firefox or Chrome (not IE!)