简体   繁体   English

如何在javascript中提醒多个输入文件值

[英]how to alert multiple input file values in javascript

i have a file input field .我有一个文件输入字段。 In that user can choose multiple files for uploading.在那个用户可以选择多个文件上传。 For that purpose i want to alert and check values which is retrieving correctly .为此,我想提醒并检查正确检索的值。

And i using Form-data to get values .我使用表单数据来获取值。 is it possible to alert Form-data values是否可以提醒表单数据值

Thanks in advance提前致谢

Yes, you can get all selected files via the files attribute.是的,您可以通过 files 属性获取所有选定的文件。

var x = document.getElementById("myFile"); 
var txt = ""; 
if ('files' in x) {
    if (x.files.length == 0) {
        txt = "Select one or more files.";
    } else {
        for (var i = 0; i < x.files.length; i++) {
            txt += "<br><strong>" + (i+1) + ". file</strong><br>";
            var file = x.files[i];
            if ('name' in file) {
                txt += "name: " + file.name + "<br>";
            }
            if ('size' in file) {
                txt += "size: " + file.size + " bytes <br>";
            }
        }
    } 
}
alert(txt);

See here for documentation请参阅此处获取文档

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM