Get label for input field

前端 未结 10 649
野趣味
野趣味 2021-01-11 09:53

I\'m doing a validation with Jquery and need to get the $label from each element with their own label. Now the alert() gives med [object object]. The best thing for me here

10条回答
  •  不思量自难忘°
    2021-01-11 10:15

     var response = ""; 
     $('input').each(function(){
         if ($(this).val() == '') {
    
         response += ", " + $('label[for="' + this.id + '"]').html();
         }
     }); 
    
    alert(response.replace(", ", "You need to fill out: "));
    

提交回复
热议问题