如何从FileList中删除文件 [英] How do I remove a file from the FileList

查看:582
本文介绍了如何从FileList中删除文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用HTML5构建一个拖放到上传的Web应用程序,我将文件放在div上,当然也可以获取dataTransfer对象,这给了我一个 FileList 。



现在我要删除一些文件,但我不知道如何,或者甚至是可能的。



最好我想从FileList中删除它们;我没有用他们但是如果不可能,那么我应该写代码中与FileList交互的检查?这样看起来很麻烦。

解决方案

如果您只想删除几个选定的文件:你不能。您链接到的文件API工作草案包含一条注释:


HTMLInputElement 界面
[HTML5]具有只读 FileList
属性,[...]

[emphasis mine]


阅读一下HTML 5工作草案,我发现了常用输入元素API 。您可以通过设置输入属性来删除整个文件列表对象为空字符串,如:

  document.getElementById('multifile')。value =; 

BTW,文章使用Web应用程序的文件也可能令人感兴趣。


I'm building a drag-and-drop-to-upload web application using HTML5, and I'm dropping the files onto a div and of course fetching the dataTransfer object, which gives me the FileList.

Now I want to remove some of the files, but I don't know how, or if it's even possible.

Preferably I'd like to just delete them from the FileList; I've got no use for them. But if that's not possible, should I instead write in checks in code that interacts with the FileList? That seems cumbersome.

解决方案

If you want to delete only several of the selected files: you can't. The File API Working Draft you linked to contains a note:

The HTMLInputElement interface [HTML5] has a readonly FileList attribute, […]
[emphasis mine]

Reading a bit of the HTML 5 Working Draft, I came across the Common input element APIs. It appears you can delete the entire file list by setting the value property of the input object to an empty string, like:

document.getElementById('multifile').value = "";

BTW, the article Using files from web applications might also be of interest.

这篇关于如何从FileList中删除文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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