Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
185 views
in Technique[技术] by (71.8m points)

javascript - html 'input = multiple' count number of selected files

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

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

1 Reply

0 votes
by (71.8m points)

try this:-

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

Demo


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...