我正在使用jquery驗證我的註冊表單,它工作正常,但我遇到了問題。我檢查電子郵件是否存在,如果電子郵件確實存在,我收到一條錯誤消息。現在我想編輯這個,所以,如果電子郵件是免費使用的。錯誤消息將變爲:此電子郵件可免費使用。jQuery驗證表單遠程規則,成功消息
$(document).ready(function(){
$("#registratieform").validate({
rules: {
email: {
required: true,
email: true,
remote: {
url: "includes/check_email.php",
type: "post",
complete: function(data){
if(data.responseText == "false") {
alert("Free");
}
}
},
},
},
messages: {
email: {
required: "This field is required",
email: "Please enter a valid email address",
remote: jQuery.format("{0} is already taken")
},
},
});
});
警報有效,但是此消息必須出現在出現錯誤的標籤中。這可能嗎?
嘗試不帶窗體元素ID。也許你可以使用類選擇器作爲目標表單對象。喜歡這個; $(「.selector」)。validate({debug:true })因此,您可以獲取無效的元素「id」。之後,您可以將消息追加到目標對象。更多細節http://docs.jquery.com/Plugins/Validation/validate#options – Kerberos 2012-07-05 11:19:42