开发者

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

开发者 https://www.devze.com 2023-01-14 20:52 出处:网络
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 n

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?


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:

  • Input.multiple — MDC
  • File — MDC
0

精彩评论

暂无评论...
验证码 换一张
取 消