Possible Duplicate:
Retrieving file names out of a multi-file upload control with javascript可能重复:使用javascript从多文件上传控件中检索文件名
From HTML5 input type="file" allows users to choose multiple files by adding the multiple="multiple" :
从HTML5输入type =“file”允许用户通过添加multiple =“multiple”来选择多个文件:
<input type="file" multiple="multiple" />
My question is: how can I get the value of that input? When using the .value it only returns the filename of the first file selected, but when choosing more than one I am not able to view the other ones.
我的问题是:我如何获得该输入的值?使用.value时,它只返回所选第一个文件的文件名,但是当选择多个文件时,我无法查看其他文件。
What I have:
我拥有的:
<input type="file" multiple="multiple" onchange="alert(this.value)"
onmouseout="alert(this.value) />
which as I told you, is only showing the name of one of the selected files.
正如我告诉你的那样,它只显示其中一个选定文件的名称。
NOTE: I don't want to edit the value (I know that is not possible) only the name of the files
注意:我不想编辑值(我知道这是不可能的)只有文件的名称
Thanks!
谢谢!
2 个解决方案
#1
78
The files selected are stored in an array: [input].files
选择的文件存储在一个数组中:[input] .files
For example, you can access the items
例如,您可以访问这些项目
// assuming there is a file input with the ID `my-input`...
var files = document.getElementById("my-input").files;
for (var i = 0; i < files.length; i++)
{
alert(files[i].name);
}
For jQuery-comfortable people, it's similarly easy
对于jQuery舒适的人来说,它同样容易
// assuming there is a file input with the ID `my-input`...
var files = $("#my-input")[0].files;
for (var i = 0; i < files.length; i++)
{
alert(files[i].name);
}
#2
10
You use input.files
property. It's a collection of File objects and each file has a name
property:
您使用input.files属性。它是File对象的集合,每个文件都有一个name属性:
onmouseout="for (var i = 0; i < this.files.length; i++) alert(this.files[i].name);"
#1
78
The files selected are stored in an array: [input].files
选择的文件存储在一个数组中:[input] .files
For example, you can access the items
例如,您可以访问这些项目
// assuming there is a file input with the ID `my-input`...
var files = document.getElementById("my-input").files;
for (var i = 0; i < files.length; i++)
{
alert(files[i].name);
}
For jQuery-comfortable people, it's similarly easy
对于jQuery舒适的人来说,它同样容易
// assuming there is a file input with the ID `my-input`...
var files = $("#my-input")[0].files;
for (var i = 0; i < files.length; i++)
{
alert(files[i].name);
}
#2
10
You use input.files
property. It's a collection of File objects and each file has a name
property:
您使用input.files属性。它是File对象的集合,每个文件都有一个name属性:
onmouseout="for (var i = 0; i < this.files.length; i++) alert(this.files[i].name);"