郁闷,触发file元素的click()方法后得到的文件无法上传!?
不知道是不是IE6.0的新特性。下面是出错的试验代码:
<form name=f>
<input name="file1" type="file" style="margin-right:-70"/><input type="button" value="浏览..." onclick="previousSibling.click()">
<input name="file2" type="file" style="margin-right:-70"/><input type="button" value="浏览..." onclick="previousSibling.click()">
<input name="file3" type="file" style="margin-right:-70"/><input type="button" value="浏览..." onclick="previousSibling.click()">
<input type=submit>
</form>
选中三个文件后提交,第一个file清空了,再点,第二个也没了...
奇怪的是163邮箱不知道用了什么方法,同样用click(),它却能上传!
问题点数:200、回复次数:13Top
1 楼net_lover(【孟子E章】)回复于 2004-09-03 19:33:05 得分 0
<form name=f enctype="multipart/form-data">Top
2 楼net_lover(【孟子E章】)回复于 2004-09-03 19:33:20 得分 0
<form name=f method="post" enctype="multipart/form-data">
Top
3 楼butcher2002(我又出来捣乱了)回复于 2004-09-03 19:51:04 得分 0
enctype="multipart/form-data"
是上传文件必须用的属性。。。。。
Top
4 楼xkou(九天神龙)回复于 2004-09-03 20:07:41 得分 0
可能又是微软给弄的吧
网易也是用的他的click()事件吗?
Top
5 楼themedy(太菜了)回复于 2004-09-04 10:27:30 得分 0
关注。。。Top
6 楼lakesea(飘渺海)回复于 2004-09-05 20:13:56 得分 0
你调onClick做什么用?
我在上传时调用过onChange都没有问题啊Top
7 楼fason(咖啡人生)回复于 2004-09-06 08:43:44 得分 200
呵呵,这个早就发现,原因就不知道了.后来我找到另一种方法
<input id=a size=20><button>选择文件</button>
<div style="position:absolute;top:0;left:-80;width:150;filter:alpha(opacity=0)" >
<input type="file" onpropertychange="a.value=this.value" size=33>
</div>
Top
8 楼emu_ston(祝福后山)回复于 2004-09-06 09:31:34 得分 0
呵呵,我原来还打算暴露一个“浏览...”按钮出来给人点呢,fason干脆把它给透明了,高,实在是高!Top
9 楼woyingjie(Hobo)回复于 2004-09-06 09:39:55 得分 0
<form action=upfile.asp enctype="multipart/form-data">
<input type="file" id="upfile" style="width=200px;">
<span style="position:relative;left:-80px;width=80;">
<input type=button onclick="upfile.click();" value=样式随你设>
</span>
<span style="position:relative;left:-80px;">
<input type="submit" value="上传">
</span>
</form>
Top
10 楼butcher2002(我又出来捣乱了)回复于 2004-09-06 09:40:19 得分 0
对于上传enctype="multipart/form-data是必须的啊!Top
11 楼emu_ston(祝福后山)回复于 2004-09-06 09:52:14 得分 0
这是163的做法,其实也挺漂亮的。实际使用的时候把iframe的宽和高设为0。
为了在一个网页里面写完,没有把框架网页写成单独的文件而用了write来生成,实际使用的时候可以用单独的内嵌网页文件。
<iframe name=fileList></iframe>
<SCRIPT LANGUAGE="JavaScript">
<!--
fileList.document.write("<form name=f action='http://www.csdn.net'>");
fileList.document.write("<input type=file name=f0>");
fileList.document.write("<input type=file name=f1>");
fileList.document.write("<input type=file name=f2>");
fileList.document.write("</form>");
//-->
</SCRIPT>
<BR>
<input name="file0">
<input type="button" value="浏览..." onclick="fileList.document.f.f0.click();file0.value=fileList.document.f.f0.value">
<BR>
<input name="file1">
<input type="button" value="浏览..." onclick="fileList.document.f.f1.click();file1.value=fileList.document.f.f1.value">
<BR>
<input name="file2">
<input type="button" value="浏览..." onclick="fileList.document.f.f2.click();file2.value=fileList.document.f.f2.value">
<BR>
<input type=button onclick="fileList.document.f.submit();" value="提交">
Top
12 楼emu_ston(祝福后山)回复于 2004-09-06 09:57:52 得分 0
woyingjie(killerj.style.display == "none";)(隐身中..........) :
你没给file控件name属性,而没有name属性的控件是不提交的。
Top
13 楼dsclub(任搏软)回复于 2004-09-06 10:25:28 得分 0
fason,这样也想得出,佩服Top
相关问题
- 怎样获得触发事件的元素的上层元素
- 如何用脚本触发<select>元素的点击事件?
- 如何触发.ascx文件中DropDownList的AutoPostBack事件???
- 为何Global.asax文件中的Session_End不能触发?
- 关闭窗口时如何触发Global.asax文件中的Session_End事件
- 我写了一个触发器,当数据更新时,写到XML文件
- 在线等待,百分相送。如何在触发器实现每次触发时将被触发的表的某列(如主键)作为文件名生成一个文本文件?
- 请问VB程序怎样获取webbrowser里的页面的触发事件的元素
- 100分求VB难题答案,VB程序怎样获取webbrowser里的页面的触发事件的元素
- 触发一个事件怎么样使页面的元素非编辑状态(可以垮框架)。




