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

Categories

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

jquery - Retrieving file names out of a multi-file upload control with javascript

The HTML is:

<input type="file" multiple="multiple" name="upload" id="id_upload" />

If I load up three files, document.getElementById("id_upload").value only returns a single file name and not an array of three names or comma separated string of three names. Same story with jQuery val(). Is there a way to get the whole list?

See Question&Answers more detail:os

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

1 Answer

0 votes
by (71.8m points)

Use the .files property of that element:

var elem = document.getElementById("id_upload");
var names = [];
for (var i = 0; i < elem.files.length; ++ i) {
   names.push(elem.files[i].name);
}

Reference:


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...