jQuery determines that multiple instances of input file cannot be empty
- 2020-06-19 09:38:46
- OfStack
For example, input with two images must upload an image:
html
Select the file 1 : <input type="file" name="myfile[]" class="myfile">
Select the file 2 : <input type="file" name="myfile[]" class="myfile">
js
if($(".myfile").length == 2){
$(".myfile").each(function(){
if($(this).val() == "") {
alert(" Please upload pictures! ");
flag = 0;
}
});
}else if($(".myfile").length !=2 ){
alert(" Pictures must not be less than 2 Zhang! ");
}