如何计算选定的文件 [英] How to count selected files
本文介绍了如何计算选定的文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我的表单非常简单,输入方式如下:
I have very simple form, with input like this:
<input id="my_id" multiple="true" type="file" name="image_name[]" />
现在我有两个问题:
- 如何使用jQuery或纯JavaScript计算选定的文件?
- 如何限制文件选择,比方说10,因为现在它是无限的?
推荐答案
如果输入类型文件
值以文件
存储在数组
中,密钥为 name
。
in case of input type file
the value is stored in array
as files
with key name
.
$('input#my_id').change(function(){
var files = $(this)[0].files;
if(files.length > 10){
alert("you can select max 10 files.");
}else{
alert("correct, you have selected less than 10 files");
}
});
小提琴示例: http://jsfiddle.net/nze2B/3/
这篇关于如何计算选定的文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文