郁闷,触发file元素的click()方法后得到的文件无法上传!?

emu_ston 2004-09-03 07:28:15
不知道是不是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(),它却能上传!
...全文
537 13 打赏 收藏 转发到动态 举报
写回复
用AI写文章
13 条回复
切换为时间正序
请发表友善的回复…
发表回复
dsclub 2004-09-06
  • 打赏
  • 举报
回复
fason,这样也想得出,佩服
emu_ston 2004-09-06
  • 打赏
  • 举报
回复
woyingjie(killerj.style.display == "none";)(隐身中..........) :

你没给file控件name属性,而没有name属性的控件是不提交的。
emu_ston 2004-09-06
  • 打赏
  • 举报
回复
这是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="提交">
butcher2002 2004-09-06
  • 打赏
  • 举报
回复
对于上传enctype="multipart/form-data是必须的啊!
woyingjie 2004-09-06
  • 打赏
  • 举报
回复
<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>
emu_ston 2004-09-06
  • 打赏
  • 举报
回复
呵呵,我原来还打算暴露一个“浏览...”按钮出来给人点呢,fason干脆把它给透明了,高,实在是高!
fason 2004-09-06
  • 打赏
  • 举报
回复
呵呵,这个早就发现,原因就不知道了.后来我找到另一种方法

<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>

lakesea 2004-09-05
  • 打赏
  • 举报
回复
你调onClick做什么用?
我在上传时调用过onChange都没有问题啊
themedy 2004-09-04
  • 打赏
  • 举报
回复
关注。。。
xkou 2004-09-03
  • 打赏
  • 举报
回复
可能又是微软给弄的吧

网易也是用的他的click()事件吗?
butcher2002 2004-09-03
  • 打赏
  • 举报
回复
enctype="multipart/form-data"

是上传文件必须用的属性。。。。。
孟子E章 2004-09-03
  • 打赏
  • 举报
回复
<form name=f method="post" enctype="multipart/form-data">
孟子E章 2004-09-03
  • 打赏
  • 举报
回复
<form name=f enctype="multipart/form-data">
什么是SWFUpload?   SWFUpload是一个客户端文件上传工具,最初由Vinterwebb.se开发,它通过整合Flash与JavaScript技术为WEB开发者提供了一个具有丰富功能继而超越传统标签的文件上传模式。 [编辑本段]SWFUpload的主要特点   * 可以同时上传多个文件;   * 类似AJAX的无刷新上传;   * 可以显示上传进度;   * 良好的浏览器兼容性;   * 兼容其他JavaScript库 (例如:jQuery, Prototype等);   * 支持Flash 8和Flash 9;   SWFUpload不同于其他基于Flash构建的上传工具,它有着优雅的代码设计,开发者可以利用XHTML、CSS和JavaScript来随心所欲的定制它在浏览器下的外观;它还提供了一组简明的JavaScript事件,借助它们开发者可以方便的在文件上传过程中更新页面内容来营造各种动态效果。   在使用SWFUpload之前,请确认你具备一定的JavaScript和DOM知识。在实际开发中,大部分的错误都是由于错误的设置和低劣的Event Handlers处理程序所造成的。 [编辑本段]文档中文翻译   http://www.v-sky.com/doc/swfupload/v2.1.0/Documentation.html [编辑本段]效果演示   * Classic Form Demo http://demo.swfupload.org/formsdemo ;   * Features Demo http://demo.swfupload.org/featuresdemo ;   * Application Demo http://demo.swfupload.org/applicationdemo ;   * v1.0.2 Plugin Demo http://demo.swfupload.org/v102demo ; [编辑本段]选择合适的Flash控件   在发行包(SWFUpload v2)中含有2个版本的Flash控件(swfupload_f8.swf 与wfupload_f9.swf),其中第一个版本拥有最佳的兼容性,但是为此损失了部分功能;而第二个版本提供了一些附加的功能但是损失了兼容性。 [编辑本段]SWFUpload的初始化与配置   首先,在页面中引用SWFUpload.js ,如      然后,初始化SWFUpload ,如   var swfu;   window.onload = function () {   swfu = new SWFUpload({   upload_url : "http://www.swfupload.org/upload.php",   flash_url : "http://www.swfupload.org/swfupload_f9.swf", file_size_limit : "20480"   });   };   以下是一个标准的SWFUpload初始化设置所需的参数,你可以根据需要自己进行删减:   {   upload_url : "http://www.swfupload.org/upload.php", 处理上传请求的服务器端脚本URL   file_post_name : "Filedata", 是POST过去的$_FILES的数组名   post_params : {   "post_param_name_1" : "post_param_value_1",   "post_param_name_2" : "post_param_value_2",   "post_param_name_n" : "post_param_value_n"   },   file_types : "*.jpg;*.gif", 允许上传文件类型   file_types_description: "Web Image Files", 文件类型描述   file_size_limit : "1024", 上传文件体积上限,单位MB   file_upload_limit : 10, 限定用户一次性最多上传多少个文件,在上传过程中,该数字会累加,如果设置为“0”,则表示没有限制   file_queue_limit : 2, 上传队列数量限制,该项通常不需设置,会根据file_upload_limit自动赋值   fl