문제

When dragging and dropping a file into <div> for getting the filelist object i used var files=e.originalEvent.dataTransfer.files; but when selecting a file from the upload window i do not know what to use.

Check this jsfiddle.

What should I use to get the filelist from the <input type="file">?

도움이 되었습니까?

해결책

any jQuery object have it's DOM element accessed using [], for example

$('input[type=file]')[0].files;

To your fiddle, it would be:

var files = this.files;

no need for jQuery in this case, because of the change event

See the updated fiddle http://jsfiddle.net/qdJ2T/1/

다른 팁

different methods to access the FileList object :

$("#btStartUpload").on("click", function(evt) {        

        var filesSelected = document.getElementById('btInput').files; // FileList object
        var filesSelected = $('#btInput').prop('files'); // with jQuery
        var filesSelected = $('#btInput')[0].files; // with jQuery
        var filesSelected = $('input[type=file]')[0].files;  // with jQuery
        console.log(filesSelected);

        // action
    });  
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top