Validation is a very powerful plug-in written by jquery's certificate users. Its functions are not enough. It is also very informative and can be customized to many things, in this case, seven callback requests are introduced, making it easier to use validation.
Version
Jquery: 1.4.2
Validation: 1.7
Resource
Validation Official Website
Jsfiddle was added to the webpage
For example, you can use the result to verify the rows.
Result
7 callback
Callback |
Description |
Reset Value |
Submithandler |
Before submit, and all the creden are successful, you can change them here to use $. Ajax () for sending. |
Default (native) form submit |
Invalidhandler |
The verification code is missing before the submit. |
No |
Success |
The verification code is successful. The verification data is error, not the direction of the verification code, or text. If the text is added to the error class. |
"Valid" |
Highlight |
Loss of a single certificate, which is the opposite of a bank certificate |
Function (element, errorclass, validclass ){ Element. addclass (errorclass). removeclass (validclass) } |
Unhighlight |
The certificate is successfully renewed, and the quantity is the opposite of the certificate. |
Function (element, errorclass, validclass ){ Element. addclass (validclass). removeclass (errorclass) } |
Showerrors |
The call back shown in the response message cannot be obtained. It is not called only when an error occurs, but is called as long as an event occurs, including a verification code. |
Defaultshowerrors |
Errorplacement |
Add function of error Element |
Function (element, error ){ Element. After (error ); } |
Note 1: All seven callback have preset values. If the value is like highlight after overwriting, there will be no original effect. If you want to retain the original effect, add the original code.
Note 2: The cursor data is not a text or jquery object.
Submithandler
Launch time: After the submit is pressed, the bank will issue the verification code, so the verification code is successful before the form. Submit call.
$ ("Form"). Validate ({submithandler: function (form) {// you can use $. Ajax () to send it here. $. Post (URL, Data, successcallback); Return false; // return false will block the original form submit. }});
Invalidhandler
Generation Time: After the submit is pressed, the bank certificate will be issued.
$("form").validate({ invalidHandler:function(form){ $("#summary").fadeOut().fadeIn(); } });
Success
Launch time: when each certificate pair is successfully issued to the certificate.
Note: The parameter number is an error, that is, the information sent to the backend by the notification token.
$ ("Form "). validate ({success: function (error) {// because of success, if it is a text that represents the classname when the error is successful, the classname will crash when it is changed to function. // Unlike highlight, classname classes are in the validclass and errorclass variations. // Add the OK text error. addclass ('valid'). Text ('OK ');}});
Highlight
Launch time: the time when each certificate pair reports a loss to the certificate.
$ ("Form "). validate ({highlight: function (element, errorclass, validclass) {// because of overwriting, you need to add the reset effect $ (element ). addclass (errorclass ). removeclass (validclass); // adds the fadeout and fadein effects $ (element ). fadeout (). fadein ();}});
Unhighlight
Launch time: when each certificate pair is successfully issued to the certificate.
$ ("Form "). validate ({unhighlight: function (element, errorclass, validclass) {// because of overwriting, you need to add the reset effect on yourself $ (element ). removeclass (errorclass ). addclass (validclass );}});
Showerrors
Launch time: every time a certificate is issued, it includes success or failure. I personally think it is more intuitive to change it to showmessages or rendermessages.
$ ("Form "). validate ({showerrors: function () {// Add the summary of vertex counts $ ("# summary" example .html ("Your form contains" + this. numberofinvalids () + "errors, see details below. "); // do not call defashowshowerrors. Other methods such as highlight and unhighlight will not be called this. defaultshowerrors ();}});
Errorplacement
Generation Time: When an error is added to each Token, you do not want to add the parameter to the end before overwriting the function.
$ ("Form "). validate ({errorplacement: function (error, element) {// Add error to the next TD. appendto (element. parent ('td '). next ('td '));}});