Prevent focus on field when it fails validation

后端 未结 4 1756
醉梦人生
醉梦人生 2021-01-12 14:14

I often use this jQuery validation plugin to validate forms and it works great. Really pleased with it, but when you press Submit on a form it automatically puts focus on th

4条回答
  •  深忆病人
    2021-01-12 15:15

    $("#myform").validate({
    onfocusout: false,
    invalidHandler: function(form, validator) {
        var errors = validator.numberOfInvalids();
        if (errors) {                    
            validator.errorList[0].element.focus();
        }
    } 
    });
    

提交回复
热议问题