Javascript jQuery 成功验证
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/1863448/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
jQuery Validation on Success
提问by uran
Hey guys thanks in advance for all your help! I have this registration form which is then validated using "bassistance's" validate.js:
嘿家伙提前感谢您的所有帮助!我有这个注册表单,然后使用“bassistance's”validate.js 进行验证:
$('#pForm').validate({
rules: {
fname: "required",// simple rule, converted to {required:true}
lname: "required",
accType: "required",
country: "required",
email: {// compound rule
required: true,
email: true
},
city: "required"
},
success: function(){
$('#pForm').hide('slow');
$('#accForm').show('slow');
}
});//form validate
Now, validation is working fine... except the success tag (which I've added)... so, although it says that fields are required, it goes ahead and reads the code under "success" as soon as I change one field. Any ideas how I can get around this one? Oh... and is there an "onFailure" type of tag is jQuery?
现在,验证工作正常......除了成功标签(我已经添加)......所以,虽然它说字段是必需的,但只要我改变一个字段,它就会继续读取“成功”下的代码场地。有什么想法可以解决这个问题吗?哦......还有一种“onFailure”类型的标签是jQuery吗?
回答by r00fus
Seems your success:callback is improperly defined, it must have one string argument as described in the documentation:
似乎您的成功:回调定义不正确,它必须具有文档中描述的一个字符串参数:
successString, Callback
If specified, the error label is displayed to show a valid element. If a String is given, its added as a class to the label. If a Function is given, its called with the label (as a jQuery object) as its only argument. That can be used to add a text like "ok!".
成功字符串,回调
如果指定,则显示错误标签以显示有效元素。如果给出字符串,则将其作为类添加到标签中。如果给定一个函数,则使用标签(作为 jQuery 对象)作为其唯一参数调用它。这可用于添加诸如“ok!”之类的文本。
Does it work when you provide a simple class-name string instead of the callback?
当您提供简单的类名字符串而不是回调时,它是否有效?

![Javascript 错误:[$compile:nonassign] 与指令“myFacebook”一起使用的表达式“undefined”是不可分配的](/res/img/loading.gif)