最新消息:Welcome to the puzzle paradise for programmers! Here, a well-designed puzzle awaits you. From code logic puzzles to algorithmic challenges, each level is closely centered on the programmer's expertise and skills. Whether you're a novice programmer or an experienced tech guru, you'll find your own challenges on this site. In the process of solving puzzles, you can not only exercise your thinking skills, but also deepen your understanding and application of programming knowledge. Come to start this puzzle journey full of wisdom and challenges, with many programmers to compete with each other and show your programming wisdom! Translated with DeepL.com (free version)

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

matteradmin12PV0评论

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
Post a comment

comment list (0)

  1. No comments so far