如何更改文件输入的文件列表 [英] how to change the file input's filelist

查看:77
本文介绍了如何更改文件输入的文件列表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有类型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 its files list. Example:

<input type = "file" id = "fileinput" />
<script type = "text/javascript>
  document.getElementById("fileinput").files = [10];
</script>

The problem is that the fileinput element's files 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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆