如何获取文件上载输入选择的文件列表 [英] How to get a list of files selected by an a file upload input

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

问题描述

我有一个元素(允许多个文件上传)。我想使用javascript / jquery来获取已选择上传的文件列表。这可能吗?

I have a element (that allows multiple file uploads). I would like to use javascript/jquery to get a list of the files that have been selected for upload. Is this possible?

元素看起来像

<input type="file" name="files[]" multiple/>

我收到带有Play Framework(Java)控制器的文件 - 但是这对于问题。

I am receiving the files with a Play Framework (Java) controller - however that's not really useful for the question.

推荐答案

您可以从输入元素的files属性中获取列表。我认为这个链接可以帮到你。 Javascript获取文件数量及其文件名来自具有多个属性的文件输入元素?

You can get the list from the input element's "files" property. I think this link can help you. Javascript get number of files and their filenames from file input element with multiple attribute?

示例:

$files = $('#fileInput').files;
for (var i=0, l=files.length; i<l; i++) {
     console.log(files[i].name);
}

这篇关于如何获取文件上载输入选择的文件列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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