Check if inputs are empty using jQuery

前端 未结 18 872
灰色年华
灰色年华 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:40

    Consider using the jQuery validation plugin instead. It may be slightly overkill for simple required fields, but it mature enough that it handles edge cases you haven't even thought of yet (nor would any of us until we ran into them).

    You can tag the required fields with a class of "required", run a $('form').validate() in $(document).ready() and that's all it takes.

    It's even hosted on the Microsoft CDN too, for speedy delivery: http://www.asp.net/ajaxlibrary/CDN.ashx

提交回复
热议问题