简体   繁体   中英

Is it possible to read files from multiple input fields?

So for example, If I have a form that contains multiple input fields with type set to 'file', is it possible to read the file you uploaded from a certain input field with same class.

for example:

<input type = "file" class = "fileSelector"/>
<input type = "file" class = "fileSelector"/>
<input type = "file" class = "fileSelector"/>

JS part

for(var i = 0; i < fileSelector.class; i++){
   fileSelector[i].addEventListener('change', function(){
      console.log(fileSelector[i].file)
    })
}
$(document).on('change','.fileSelector',function(){
    console.log($(this).prop('files'));
)

this would work.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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