How can I use jquery to count the length of the files from the multiple-input field?
alert($('#myForm input[type=file]').files.length);
<input type="file" multiple="multiple" name="file[]"/>
error:
$("#myForm input[type=file]").files is undefined
It works find with plain js but I don't want to use ID in my input field.
alert(document.getElementById('file').files.length);
<input type="file" multiple="multiple" name="file[]" id="file"/>
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…