Jquery Validation: How to make fields red

前端 未结 4 1542
春和景丽
春和景丽 2021-02-04 04:51

I am using jquery and jquery.validate.cs (jQuery Validation Plugin 1.8.0) to validate a form. Right now it displays a message next to a field saying : \"This is a required fiel

4条回答
  •  你的背包
    2021-02-04 05:20

    I've found this code in official docs. In this example we hightlight both wrong input and its label.

    $("#myform").validate({
       highlight: function(element, errorClass, validClass) {
        $(element).addClass(errorClass).removeClass(validClass);
        $(element.form).find("label[for=" + element.id + "]")
        .addClass(errorClass);
      },
      unhighlight: function(element, errorClass, validClass) {
        $(element).removeClass(errorClass).addClass(validClass);
        $(element.form).find("label[for=" + element.id + "]")
        .removeClass(errorClass);
      }
    });
    

    You can easily modify it for your needs.
    See full documentation here: https://jqueryvalidation.org/validate/#highlight

提交回复
热议问题