jQuery验证错误放置成功与失败 [英] JQuery Validation errorPlacement Success vs Failure
问题描述
我正在使用jQuery Validation处理表单,并且必须在输入字段旁边显示一个对号(如果输入正确),并在下面显示错误消息(例如:请输入至少4个字符")输入字段.
I'm using jQuery Validation for a form, and I have to display a checkmark next to the input field (if the entry was correct), and the error message (example:"please enter at least 4 characters") below the input field.
我当时正在考虑做这样的事情:
I was thinking of doing something like this:
errorPlacement:函数(错误,元素){
*如果验证成功*
error.appendTo($(#checkmark"));
* 否则 *
error.appendTo($(#error-message"));;
}
errorPlacement: function(error, element) {
* if the validation is succesful *
error.appendTo($("#checkmark"));
* otherwise *
error.appendTo($("#error-message"));
}
但是,如何根据需要显示的消息类型来定位不同的div目标呢?还是我完全错了,还有另一种方法可以做到这一点?
But how can you target a different div destination depending on the type of message you need to display? Or do I have it completely wrong and there's another way to do this?
谢谢!
推荐答案
您可以在jquery.validate.js文件中搜索此表达式:
You can search for this expression in jquery.validate.js file :
this.settings.success( label )
,然后将其替换为:
this.settings.success( label, element)
这个技巧可以修复jquery-validate,就像他们在文档中所说的那样.
This trick repairs jquery-validate as they told in their documentation.
这篇关于jQuery验证错误放置成功与失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!