jQuery Validation PlugIn:字段成功验证的回调? [英] jQuery Validation PlugIn : Callback for field success validation?
问题描述
我正在使用 errorPlacement 向标签添加一个类,以显示除错误文本之外的图形元素(它们都是不同的元素).
Im am using errorPlacement to add a class to a label to show a graphic element in addition to the error text ( they are both different elements).
有没有办法使用在字段验证成功时触发的回调?我已经在使用 validClass,它会更改错误消息,但我需要回调,以便将图形元素更改为成功"元素.
Is there a way to use a callback that will fire when the validation of a field is successful? I am already using validClass, that will change the error message, but I need a call back so I can change the graphic element to a "success" one.
举例
[图形] [输入字段] [错误文本]
[graphic] [input field] [error text]
当出现错误时,我能够更改 [图形] 和 [错误文本],但是当在字段中输入正确的值时,我能够更改 [错误文本] 而不是 [图形].
I was able to change the [graphic] and the [error text] when there is an error, but when the correct value is entered in the field I was able to change the [error text] but not the [graphic].
推荐答案
您可能需要查看 success
选项.
You might want to check out the success
option.
http://docs.jquery.com/Plugins/Validation/validate#options
$("#myform").validate({
success: function(label) {
label.addClass("valid").text("Ok!")
},
submitHandler: function() { alert("Submitted!") }
})
如果您将函数传递给 success
,则会将标签作为 jQuery 对象返回.然后,您可以操作该对象或相关对象.
If you pass a function to success
, you are given back the label as a jQuery object. You can then manipulate that object or a related object.
或者,您的错误和成功图形可以使用背景图片,然后您可以使用 validClass
上的 CSS 替换背景图片.
Alternatively, your error and success graphic can use a background image, and then you can swap out the background image with CSS on the validClass
.
这篇关于jQuery Validation PlugIn:字段成功验证的回调?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!