After JQuery is verified, use ajax to submit data.
1 function checkForm () {2 validator = $ ("# commentForm "). validate ({// # formId is the ID of the form to be verified 3 errorElement: "span", // error marked with "div" label, default: "label ", "span" is displayed on the right of the text box by default. // wrapper: "li", // use the "li" label and package the preceding errorELement. 5 // errorClass: "validate-error", // the css class name for the error prompt "error" 6 // onsubmit: false, // whether to verify when the form is submitted. The default value is: true 7 // onfocusout: false, // whether to verify when you obtain the focus. Default Value: true 8 // onkeyup: false, // whether to verify when you press the keyboard. Default Value: true 9 // onclick: f Alse, // whether to verify when you click the mouse (usually checkbox, radiobox) 10 // focusCleanup: false, // when the element that fails to pass the verification gets the focus, and remove the error message. The default is false11 // focusInvalid: true, // form that fails verification after the form is submitted (the first form that has not passed verification or submitted the previous focus) will get the focus, the default true12 // ignore: "# cname" // some elements are not verified, the value corresponds to the selector, if you need to ignore multiple text boxes, you can use the class selector 13 ignoreTitle: true, 14 validClass: "valid", // when the verification is successful, the css class name 15 success: function (label) is used) {// The prompt message 16 label is used when the verification is successful. addClass ("valid" pai.html ("OK! ") 17}, 18 submitHandler: function (form) {// If the verification succeeds, click the submit button to perform the operation. Note: After using this method, action = "xx" in form will expire 19 alert ('verification passed '); 20}, 21 invalidHandler: function (form, validator) {// If the verification fails, perform the following operations: 22. var errors = validator. numberOfInvalids (); // get the total number of errors 23 var message = 'your exist' + errors + 'error'; 24 // alert (message); 25}, 26 rules: {27 "x. name ": {// enter name28 required: true, // verification condition: 29 minlength3: 5, // verification condition: the minimum length is 530. maxlength3: 10, 31 checkCharType: [true, false, false, null] 32}, 33 "x. sex ": {// input box for verification name34 required: true, // verification condition: required 35 minlengty2: 5, // verification condition: Minimum Length: 536 maxlengty2: 1037}, 38}, 39 messages: {40 "x. name ": {41 required:" cannot be blank ", 42 minlength:" minimum value: 5 "43}, 44" x. sex ": {45 required:" cannot be blank ", 46 minlength:" minimum value: 5 "47} 48} 49}); 50} 51 52 function xx () {53 // alert ($ ("# commentForm "). validate (). form (); // executes form Verification and determines whether the verification is successful. If the verification succeeds, true is returned; otherwise, false54 $ ("# commentForm") is returned "). valid (); // $ ("# commentForm "). valid () indicates to run form verification 55} 56 57 function cl () {58 $ ("# commentForm "). validate (). resetForm (); // clear all error messages 59}
Reproduced to: http://blessht.iteye.com/blog/1074419