Check if inputs are empty using jQuery

前端 未结 18 1324
灰色年华
灰色年华 2020-11-22 09:14

I have a form that I would like all fields to be filled in. If a field is clicked into and then not filled out, I would like to display a red background.

Here is my

18条回答
  •  生来不讨喜
    2020-11-22 09:30

    The :empty pseudo-selector is used to see if an element contains no childs, you should check the value :

    $('#apply-form input').blur(function() {
         if(!this.value) { // zero-length string
                $(this).parents('p').addClass('warning');
         }
    });
    

提交回复
热议问题