JQuery Validation错误消息fadein

JQuery Validation error message fadein

本文关键字:fadein 消息 错误 Validation JQuery      更新时间:2023-09-26

我需要你的帮助。我离解决方案不远了,但我如何才能让错误消息以淡入显示,而不是以正常方式显示。我已经有了这个代码,我想我已经非常接近解决方案了。

$(document).ready(function() {
    $("#contactform").validate({
  errorPlacement: function(error, element) {
     error.fadeIn('.error');
  },
        messages: {
            contactname: "Required",
            email: "Invalid email",
            comment: "Invalid URL"
        }
    });
});

代替:

error.fadeIn('.error');

尝试:

$('.error').text(error).fadeIn();

试试这个:

$(function() {
    $("#contactForm").validate({
        invalidHandler: function(form, validator) {
            // not sure if this is the correct selector but I found it here: http://docs.jquery.com/Plugins/Validation/validate#toptions
            $(".error").hide().fadeIn("slow");
        },
        messages: {
            contactname: "Required",
            email: "Invalid email",
            comment: "Invalid URL"
        }
    });
});

您可以在消息下面的脚本中添加这样的部分

highlight: function (element, errorClass) {                    
                    $('label[for=' + element.id + ']').hide();
                    $('label[for=' + element.id + ']').fadeIn(5000);
                },

jsfiddle中的代码不起作用。这是解决方案。

errorPlacement: function(error, element) {
        var c = $("<span style='display: none'/>").append(error.html());
        error.empty().append(c);
        setTimeout(function(){ error.children().first().fadeIn("slow");},0);
}

@John Kalberer这对我来说很好。。。

谢谢,

$(函数(){$("#contactForm").validate({invalidHandler:函数(表单、验证器){//不确定这是否是正确的选择器,但我在这里找到了它:http://docs.jquery.com/Plugins/Validation/validate#toptions$(".error").hide().fadeIn("slow");},消息:{contactname:"必需",email:"无效电子邮件",comment:"无效URL"}});});