如何给一个file类型的input赋值?

zjtn 2001-05-16 08:14:00
加精
我试过普通的赋字符窜,如“c:/111.txt”,可是没有任何反应。
...全文
5623 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
孟子E章 2001-05-16
  • 打赏
  • 举报
回复
TO:ringphone(临风) 
==========================
由于安全方面的原因,IE4/5不支持在<input type=file>里设定值。但在NN4+里,必须先进行授权才能往<input type=file>里写值。以下是例子;在NN4.77里测试成功!!

<SCRIPT>
function test(){
if (document.layers) {
netscape.security.PrivilegeManager.enablePrivilege('UniversalFileRead');
}
document.aForm.aFile.value = 'c:\\test.txt';

}
</SCRIPT>
<FORM NAME="aForm" METHOD="post" ENCTYPE="multipart/form-data" ACTION="你的事件处理代码">
<INPUT TYPE="file" NAME="aFile">
<INPUT TYPE="button" VALUE="测试文件" onclick="test()">
</FORM>
xmlingo 2001-05-16
  • 打赏
  • 举报
回复
http://msdn.microsoft.com/
input file value Property
Retrieves the file name of the input object after the text is set by user input.
Scripting [ sValue = ] INPUT type=file.value
Possible Values
sValue String that receives the file name.
The property is read-only!!!!!!. The property has no default value.

孟子E章 2001-05-16
  • 打赏
  • 举报
回复
<body>
<form name=Form1>
Text1:<input name=txtText1 type="text" size=60>
<input type="button" value="测试" onclick="txtText1.value='c:\\test.txt'">
</form>
ringphone 2001-05-16
  • 打赏
  • 举报
回复
楼上的,回答得文不对题,有本事把上面代码改成按“测试”按钮能在fileFile1里面显示"c:\111.txt"
孟子E章 2001-05-16
  • 打赏
  • 举报
回复
<script language="javascript">
function test(){
var str1=document.Form1.fileFile1.value;
var regstr=/\\/;
var regresult=new RegExp(regstr)
var sss=str1.split(regresult,'100');
var need=sss[sss.length-1];
var a=need.split('.');
document.Form1.txtText2.value=a[0];
document.Form1.txtText3.value=a[1];
}

</script>
<body>
<form name=Form1>
File Input:<input name=fileFile1 type=file><br>

Text1:<input name=txtText1 type="text" size=60><br>
Text2:<input name=txtText2 type="text"><br>
Text3:<input name=txtText3 type="text"><br>
<input type="button" value="测试" onclick="txtText1.value=fileFile1.value"><br><br>
<input type="button" value="转换" onclick="test()">
</form>
孟子E章 2001-05-16
  • 打赏
  • 举报
回复
c:\\111.txt
zjtn 2001-05-16
  • 打赏
  • 举报
回复
原来,不能给input type=file 赋值。
这里先谢过大家的热心帮助。
但是……分应该给谁呢?

87,904

社区成员

发帖
与我相关
我的任务
社区描述
Web 开发 JavaScript
社区管理员
  • JavaScript
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧