使用jQuery获取多个文件选择的所有值 [英] Get all values of multiple file select with jQuery
本文介绍了使用jQuery获取多个文件选择的所有值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
可能重复:
从多使用javascript
Possible Duplicate:
Retrieving file names out of a multi-file upload control with javascript
知道了:
<input type="file" name="file1" multiple="multiple" />
在jQuery中使用
$("input[name=file1]").change(function() {
$("input[name=file]").val($("input[name=file1]").val());
});
现在我的问题是:它只给出第一个选定的文件,我想全部拥有它们. 谢谢!
Now my problem is this: It only gives the first selected file, I would like to have them all... How to do this? Thanks!
推荐答案
尽管我链接了注释中可能存在的重复,但这是一个纯JavaScript解决方案.如果您愿意,可以使用jQuery版本: jsFiddle示例
Although I linked to a possible dupe in the comments, it's a pure JavaScript solution. Here's a jQuery version if you like: jsFiddle example
$("input[name=file1]").change(function() {
var names = [];
for (var i = 0; i < $(this).get(0).files.length; ++i) {
names.push($(this).get(0).files[i].name);
}
$("input[name=file]").val(names);
});
这篇关于使用jQuery获取多个文件选择的所有值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文