1 function Checkform () {2Validator = $ ("#commentForm"). Validate ({//#formId为需要进行验证的表单ID3Errorelement:"span",//error marked with "div" tag, default: "Label", "Span" is displayed by default directly to the right of the text box4 //wrapper: "Li",//use the "Li" tab and wrap up the top errorelement.5 //errorclass: "Validate-error",//error prompt CSS class name "error"6 //Onsubmit:false,//whether to validate on form submission, default: True7 //Onfocusout:false,//whether to validate when the focus is taken, default: True8 //Onkeyup:false,//whether to verify when tapping the keyboard, default: True9 //Onclick:false,//whether to validate on mouse click (General validation Checkbox,radiobox)Ten //Focuscleanup:false,//When the element that is not validated is focusable and the error is removed, the default false One //Focusinvalid:true,//after a form is submitted, a form that does not pass validation (the first one or the unverified form that receives the focus before the submission) receives the focus, which is the default true A //Ignore: "#cname"//Do not validate certain elements, values correspond to selectors, if you need to ignore multiple text boxes, you can use class selector -Ignoretitle:true, -Validclass:"valid",//when validation succeeds, the CSS class name used theSuccess:function (label) {//the prompt message to use when verifying success -Label.addclass ("valid"). HTML ("ok!") - }, -Submithandler:function (form) {//If validation passes, click on the Submit button to perform the action, note: After using this method, the action= "xx" in the form will be invalidated +Alert'Validation by'); - }, +Invalidhandler:function (Form, validator) {//if validation does not pass, perform additional operations here A varErrors = Validator.numberofinvalids ();//get total number of errors at varMessage ='you exist'+ Errors +'a mistake'; - //alert (message); - }, - rules:{ - "X.name":{//input box that needs to be validated name -Requiredtrue,//verification Condition: Required inMinlength3:5,//validation Condition: Minimum length of 5 -Maxlength3:Ten, toCheckchartype: [true,false,false,NULL] + }, - "X.sex":{//input box that needs to be validated name theRequiredtrue,//verification Condition: Required *Minlength2:5,//validation Condition: Minimum length of 5 $Maxlength2:TenPanax Notoginseng }, - }, the messages:{ + "X.name":{ ARequired:"cannot be empty", theMinLength:"the minimum value is 5" + }, - "X.sex":{ $Required:"cannot be empty", $MinLength:"the minimum value is 5" - } - } the }); - }Wuyi the function xx () { - //Alert ($ ("#commentForm"). Validate (). form ());//performs form validation while judging whether validation passes, or False if passed by return true Wu$("#commentForm"). valid ();//$ ("#commentForm"). Valid () represents the form validation that runs the form - } About $ function cl () { -$("#commentForm"). Validate (). Resetform ();//Clear all the error hints -}
Reprint to: http://blessht.iteye.com/blog/1074419
After jquery validation succeeds, the data is submitted using AJAX