jQuery Validation PlugIn : Callback for field succ

2020-03-29 07:10发布

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).

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.

For Example

[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].

2条回答
Melony?
2楼-- · 2020-03-29 07:37

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!") }
})

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.


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.

查看更多
够拽才男人
3楼-- · 2020-03-29 07:39

You can override the defaults validClass: "valid" with validClass:"success"

查看更多
登录 后发表回答