JQuery validation plugin - error highlight problem

后端 未结 2 1461
春和景丽
春和景丽 2020-12-06 08:32

I have a form with two input textboxes, and I have included jQuery validation rules for both:



        
2条回答
  •  旧巷少年郎
    2020-12-06 08:58

    Found the answer, you have to provide an unhighlight property as well.

    Adds the error class to both the invalid element and its label

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

    More info

提交回复
热议问题