how to get files from <input type='file' …/> (Indirect) with javascript

后端 未结 3 895
闹比i
闹比i 2020-12-05 06:43

I have problem with \"input tag\" in non IE browsers

I\'m trying to write my uploader , just using javascript a

3条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2020-12-05 07:13

    If you are looking to style a file input element, look at open file dialog box in javascript. If you are looking to grab the files associated with a file input element, you must do something like this:

    inputElement.onchange = function(event) {
       var fileList = inputElement.files;
       //TODO do something with fileList.  
    }
    

    See this MDN article for more info on the FileList type.

    Note that the code above will only work in browsers that support the File API. For IE9 and earlier, for example, you only have access to the file name. The input element has no files property in non-File API browsers.

提交回复
热议问题