jQuery Validation PlugIn:进行字段成功验证的回调吗? [英] jQuery Validation PlugIn : Callback for field success validation?

查看:121
本文介绍了jQuery Validation PlugIn:进行字段成功验证的回调吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用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选项.

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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆