<iframe id=hello src="a.txt"></iframe>
<script language=javascript>
function e()
{
alert(document.frames("hello").document.body.innerText);
}
</script>
<input onclick="e()" type=button value=get>
<script language=javascript>
function e()
{
alert(document.frames("hello").document.body.innerText);
}
</script>
<input onclick="e()" type=button value=get>
<iframe id=hello src="http://sina.com.cn/a.txt"></iframe>
那我是不是不能实现将客户端的一个文件的内容传给服务器:
先前,我试过以下方法,可是大约由于伺服器是linux,所以不执行
var fso=new ActiveXObject(……);所以失败
是不是一定要将文件上传到服务器然后再在服务器端读这个文件。<html><head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<meta name="GENERATOR" content="Microsoft FrontPage 4.0">
<meta name="ProgId" content="FrontPage.Editor.Document">
<title>New Page 1</title>
</head><body><form name=frm>
请选择一个TXT文件:<input type=file name=theFile><input type=button value=确定 name="NowOK" onclick="getContent()"><br>
<textarea name=theFileContent rows="15" cols="50" style="display:true">
</textarea>
</form></body></html>
<script language=javascript>
function getContent()
{
if (frm.theFile.value.length<4||frm.theFile.value.search(/\.txt$/i)<1)
{
alert("没有选择文件或所选择的文件不是TXT文件");
return;
}
try
{
var fso, f
fso=new ActiveXObject("Scripting.FileSystemObject");
f=fso.OpenTextFile(frm.theFile.value,1);
document.all("theFileContent").innerText="";
var theContent="";
for (var i=0;i<10000;i++) //内容太多的话将只读到第10000行
{
try { theContent+=f.ReadLine()+"\n"; }
catch(Exception){ break; }
}
document.all("theFileContent").innerText=theContent;
}
catch(Exception){alert("请输入正确的文件");}}</script>
<script language=javascript>
function e()
{
alert(document.frames("hello").document.body.innerText);
}
</script>
<input onclick="e()" type=button value=get>把你的txt和htm文件放到一个虚拟目录下即可