Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

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 accomplish this?

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

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
183 views
Welcome To Ask or Share your Answers For Others

1 Answer

try this:-

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

Demo


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...