如何更改文件输入的文件列表 [英] how to change the file input's filelist
问题描述
我有类型
file
的这个 input
,我想改变它的文件
列表。示例:
< input type =fileid =fileinput/>
< script type =text / javascript>
document.getElementById(fileinput)。files = [10];
< / script>
$ b问题在于
fileinput
元素的文件 code> list is not set。
解决方案出于安全原因,浏览器阻止javascript改变将被上传的文件:只有用户可以通过用户界面选择文件,这是为了防止邪恶的脚本上传
/ etc / passwd
,例如,没有用户知道。
有一个例外是在表单上调用reset会清除文件或文件列表,但不能以编程方式添加。
I have this
input
of type"file"
, and I want to change itsfiles
list. Example:<input type = "file" id = "fileinput" /> <script type = "text/javascript> document.getElementById("fileinput").files = [10]; </script>
The problem is that the
fileinput
element'sfiles
list is not set. How do I do it?解决方案For security reasons, browsers prevent javascript from changing the files which will be uploaded: only the user can select files via the user interface. This is to prevent an evil script to upload
/etc/passwd
, for example, without the user knowing.The one exception is that calling "reset" on the form will clear the file or filelist, but you can never add to programmatically.
这篇关于如何更改文件输入的文件列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!