当前位置: 动力学知识库 > 问答 > 编程问答 >

javascript - JQuery Validation error message fadein

问题描述:

i need your help. I am not very far from the solution but how can i make the errors messages display with a fade in instead of the normal way. I have this code already, i think i am very close to the solution.

$(document).ready(function() {

$("#contactform").validate({

errorPlacement: function(error, element) {

error.fadeIn('.error');

},

messages: {

contactname: "Required",

email: "Invalid email",

comment: "Invalid URL"

}

});

});

网友答案:

Instead of:

error.fadeIn('.error');

Try:

$('.error').text(error).fadeIn();
网友答案:

Try this:

$(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"
        }
    });
});
网友答案:

you can add a section like this in your script below messages

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

                },
网友答案:

your code in jsfiddle does not work. Here is the solution.

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 This worked for me just fine ...

thanks,,

$(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" } }); });

分享给朋友:
您可能感兴趣的文章:
随机阅读: