admin管理员组

文章数量:1398794

I have a multiple file input like this:

<input multiple="multiple" type="file" name="file">

When I click it, I get the option to select some files. When I select some files click on "open", I need to display the number of files I selected (let's say in an alert box). I suppose there should be a javascript event to handle this situation, but I can't find it. How could I acplish this?

I have tried searching around stackoverflow but haven't found a solution, although this question doesn't seem overly specific.

I have a multiple file input like this:

<input multiple="multiple" type="file" name="file">

When I click it, I get the option to select some files. When I select some files click on "open", I need to display the number of files I selected (let's say in an alert box). I suppose there should be a javascript event to handle this situation, but I can't find it. How could I acplish this?

I have tried searching around stackoverflow but haven't found a solution, although this question doesn't seem overly specific.

Share Improve this question asked Aug 12, 2014 at 12:39 icarusicarus 1661 gold badge6 silver badges14 bronze badges 3
  • 1 possible duplicate of HTML5: How to count the length of the files from the multiple-input field – MrUpsidown Commented Aug 12, 2014 at 12:51
  • 1 How to count selected file Demo – Shubh Commented Aug 12, 2014 at 12:54
  • 1 @MrUpsidown: thank you, I haven't stumbled across that question and I searched a great deal for this issue.. I'll pay more attention next time. – icarus Commented Aug 12, 2014 at 13:00
Add a ment  | 

2 Answers 2

Reset to default 3

try this:-

$("input[type='file']").on("change", function(){  
  var numFiles = $(this).get(0).files.length
   alert(numFiles);
});

Demo

$("input[type='file']").eq(0).files.length;

本文标签: javascripthtml 39inputmultiple39 count number of selected filesStack Overflow