Ruu*_*uub 6 validation ajax jquery message
我正在使用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")
},
},
});
});
Run Code Online (Sandbox Code Playgroud)
警报有效,但此消息必须出现在错误所在的标签中.这可能吗?
您可以使用success选项。
如果指定,则会显示错误标签以显示有效元素。如果给出了字符串,则会将其作为类添加到标签中。如果给定了一个函数,则使用标签(作为 jQuery 对象)和经过验证的输入(作为 DOM 元素)来调用它。该标签可用于添加类似 \xe2\x80\x9cok!\xe2\x80\x9d 的文本。
\n\n文档中的示例:将类 \xe2\x80\x9cvalid\xe2\x80\x9d 添加到有效元素,通过 CSS 设置样式,并添加文本 \xe2\x80\x9cOk!\xe2\x80\x9d。
\n\n$("#myform").validate({\n success: function(label) {\n label.addClass("valid").text("Ok!")\n },\n submitHandler: function() { alert("Submitted!") }\n});\nRun Code Online (Sandbox Code Playgroud)\n\n在你的代码中:
\n\n$(document).ready(function(){\n $("#registratieform").validate({\n rules: {\n email: {\n required: true,\n email: true,\n remote: {\n url: "includes/check_email.php",\n type: "post",\n complete: function(data){\n if( data.responseText == "false" ) {\n alert("Free");\n }\n }\n },\n },\n },\n\n messages: {\n email: {\n required: "This field is required",\n email: "Please enter a valid email address",\n remote: jQuery.format("{0} is already taken")\n },\n },\n\n success: function(e) {\n // Remove error message\n // Add success message\n },\n });\n});\nRun Code Online (Sandbox Code Playgroud)\n\n我建议阅读:.validate()
\n| 归档时间: |
|
| 查看次数: |
16181 次 |
| 最近记录: |