将输入文件值设置为第二个输入文件 [英] Set input file value to second input file
问题描述
注意:
答案&下面的评论反映了2009年旧版浏览器的状态。现在,您可以在2017年使用JavaScript动态/编程地设置文件输入元素的值。
查看答案此问题的详细信息以及演示:
如何以编程方式设置文件输入值(即:何时拖放文件)?
我有2 input type =file
< input type =fileid =attach_file_1name =attach_file_1/>
< input type =fileid =attach_file_2name =attach_file_2/>
在为 attach_file_1
选择文件后,可以使用javascript为 attach_file_2
设置相同的值?
我不认为你可以。我相信这是一个安全问题。您无法设置文件输入类型的值。否则,您可以隐藏文件输入元素,并在用户不知情的情况下将文件上传到您的服务器。
Note:
The answers & comments below reflect the state of legacy browsers in 2009. Now you can actually set the value of the file input element dynamically/programatically using JavaScript in 2017.
See the answer in this question for details as well as a demo:
How to set file input value programatically (i.e.: when drag-dropping files)?
I have 2 input type="file"
<input type="file" id="attach_file_1" name="attach_file_1" />
<input type="file" id="attach_file_2" name="attach_file_2" />
after "choosing" file for attach_file_1
, there is possible to set same value for attach_file_2
using javascript ?
I don't think you can. I believe it's a security issue. You can't set the value of a file input type. Otherwise you could hide the file input element and upload a file to your server without the user's knowledge.
这篇关于将输入文件值设置为第二个输入文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!