最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

jquery - Javascript, count how many files were attached to a file upload input - Stack Overflow

programmeradmin11浏览0评论

I have this file input:

<input type="file" name="photo[]" multiple="yes">

What I want is, when someone uploads a file/files to it, I want to alert them how many files were uploaded (altogether). Like if I upload 3 files, it will alert "3 files were uploaded". And if I add 2 more files it will alert "5 files were uploaded" (adding the 2 files uploaded before).

I have this file input:

<input type="file" name="photo[]" multiple="yes">

What I want is, when someone uploads a file/files to it, I want to alert them how many files were uploaded (altogether). Like if I upload 3 files, it will alert "3 files were uploaded". And if I add 2 more files it will alert "5 files were uploaded" (adding the 2 files uploaded before).

Share Improve this question asked Dec 7, 2013 at 7:40 ParanoidParanoid 1,9235 gold badges16 silver badges17 bronze badges
Add a comment  | 

2 Answers 2

Reset to default 11

Try this code:

var numFiles = $("input:file")[0].files.length;

you may try this too

document.forms["form_name"]["multi_files_input_name[]"].files.length
发布评论

评论列表(0)

  1. 暂无评论