How to work with FileList (from <input type=“file”>) in Javascript?

前端 未结 3 820
心在旅途
心在旅途 2020-12-11 07:24

In this W3schools example, console.log on the input element reveals a FileInput object:

FileList {0: File, 1: File, length: 2}

3条回答
  •  甜味超标
    2020-12-11 08:20

    Untested, but this should work

    var fileStore = [];
    
    function myFunction(){
        var txt = "";
        if ('files' in x) {
            if (x.files.length == 0) {
                txt = "Select one or more files.";
            } else {
                fileStore.push.apply(fileStore,x.files);
                console.log(x.files);
                console.log(fileStore);
    

    More on Function::apply

    More on Array::push

提交回复
热议问题