jQuery make sure all form fields are filled

前端 未结 4 1185
北恋
北恋 2020-12-05 15:41

I have a simple form I\'m making client side validation for. To validate, none of the fields should be left blank. This is how I go at it:

function validateF         


        
4条回答
  •  爱一瞬间的悲伤
    2020-12-05 16:07

    You were returning from the inner function not from the validate method

    Try

    function validateForm() {
        var valid = true;
        $('.form-field').each(function () {
            if ($(this).val() === '') {
                valid = false;
                return false;
            }
        });
        return valid
    }
    

提交回复
热议问题