2011-06-12 105 views
0

我需要你的幫助。我離解決方案不是很遠,但是如何使淡入淡出信息以正常方式顯示。我已經有了這個代碼,我認爲我非常接近解決方案。JQuery驗證錯誤消息fadein

$(document).ready(function() { 

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

}); 
+0

如果你說過你正在使用哪個驗證插件,它會有很多幫助。 – 2011-06-12 17:03:12

+0

我正在使用這個http://ajax.aspnetcdn.com/ajax/jquery.validate/1.8.1/jquery.validate.js,謝謝 – Carlos 2011-06-12 17:05:50

回答

0

試試這個:

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

不,它不起作用。你可以在這裏看到我所有的代碼:http://jsfiddle.net/CEscorcio/CdvGh/2/ – Carlos 2011-06-12 17:35:33

+0

你可以把一個警告框,並檢查'​​invalidHandler'是否正在射擊? – 2011-06-12 17:37:34

+0

它不是射擊 – Carlos 2011-06-12 17:42:15

0

相反的:

error.fadeIn('.error'); 

嘗試:

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

不,它不會觸發errorPlacement – Carlos 2011-06-12 18:11:41

0

您可以在下面的腳本消息

添加部分這樣
highlight: function (element, errorClass) {      
        $('label[for=' + element.id + ']').hide(); 
        $('label[for=' + element.id + ']').fadeIn(5000); 

       }, 
0

你在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); 
} 
0

@約翰Kalberer這爲我工作就好了... ...

感謝,,

$(函數(){ $( 「#聯繫形式」)。驗證({ invalidHandler:function(form,validator){ //不知道這是否是正確的選擇器,但我在這裏找到它:http://docs.jquery.com/Plugins/Validation/validate#toptions $(「。error」)。hide()。fadeIn(「slow」); } , messag es:{ contactname:「必填」, 電子郵件:「無效的電子郵件」, 評論:「無效的URL」 } }); });