? |
<html>
<head>
<title>保存文件</title>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<meta http-equiv="Content-Language" content="zh-cn">
<meta http-equiv="pragma" content="no-cache">
<script>
<!--
function saveHTMLFile(strFileName)
{
document.execCommand('saveas','true',strFileName + '.htm');
}
function saveTXTFile(strFileName)
{
document.execCommand('saveas','true',strFileName + '.txt');
}
function getSelectInfo()
{
alert('你所选的内容是:/n');
alert(document.getSelection());
}
//-->
</script>
</head>
<body>
<center>这是一个文件<p>
<INPUT TYPE="BUTTON" NAME="getstring" VALUE="得到所选信息" onClick="getSelectInfo()">
<input type=button value=另存为htm onclick="saveHTMLFile('Content')">
<input type=button value=另存为txt onclick="saveTXTFile('Content')">
<input type=button value=另存为txt onclick="document.execCommand('saveas','true','Content.txt')">
<p>测试<p>
</center>
</body>
</html>
弹出另纯为对话框 |
js写入文件
function WriteTxt()
{
var fso, tf;
fso = new ActiveXObject("Scripting.FileSystemObject");
tf = fso.CreateTextFile("C://testfile.txt", true);
tf.WriteLine("123") ;
tf.Close();
}