JQuery - get all fileNames inside input='file'

后端 未结 6 1832
忘掉有多难
忘掉有多难 2020-12-14 01:15

I have and I want to get all file names inside this input. I\'ve seen some example, but

6条回答
  •  感动是毒
    2020-12-14 01:35

    you can extend the prototype of File Object (for example File.prototype.toJSON), and you can access the FileList of :

    
    
     var file = document.getElementById('fileItem').files[0];
    

    For more information check this documentation:

    https://developer.mozilla.org/en-US/docs/Web/API/FileList#Using_the_file_list

    check this simple example:

    File.prototype.toJSON = function() {
    	return {
    		'lastModified'     : this.lastModified,
    		'lastModifiedDate' : this.lastModifiedDate,
    		'name'             : this.name,
    		'size'             : this.size,
    		'type'             : this.type 
    	};
    }
    
    function getFiles() {
        var files = document.getElementById('myFiles').files;
        document.getElementById('result').innerHTML = '

    result

    ' + JSON.stringify(files); }
    
    

    Good Luck!

提交回复
热议问题