2 3
jQuery Validation Framework:
Basic html code:
1 2 3 40 41 42 html:43
From the above code, let me talk about the use of jQuery Validation.
1.validate(options) is the beginning of running the form. It is used to verify the form you selected. The fifth line of the above code "#myForm" is the form id name.
2.rules() is the verification rule, which is the options in validate, which is theuser-defined key/value pair rule= ==The key is the name attribute of a form element, and the value is a simple string or an object consisting of rule/parameter pairs.
3. messages () is auser-defined key/value pair message===The key is The name attribute of a form element, whose value is the message to be displayed by the form element.
4. The username and password in rules() are the name values in the input.
5.When the value of required is true, verifying this item is mandatory.
6.minlength(length) sets the minimum length of the verification element.
7.maxlength(length) sets the maximum length of the verification element.
8.rangelength(range) sets a length range of the validation element.
9.max(value) sets the maximum value of the validation element.
10.min(value) sets the minimum value of the validation element.
11.range() sets the range of the pointer.
12.email() verifies whether the email format is correct.
13.url() Verify whether the URL format is correct.
14.date() verifies whether the date format is correct. [Note:does not verify the accuracy of the date, only the format]
15.submitHandler When the form is passed Verify and submit the form.
// 校验全部通过 submitHandler: function () { alert("校验全部通过!") },
16.invalidHandler When a form that fails validation is submitted, you can Handle some stuff in that callback function.
// 校验不通过 invalidHandler: function () { alert("no") },
17.focusInvalidThe default value is true. When the verification fails, the focus jumps to the first invalid form element.
18.focusCleanupThe default value is true,When the form gets focus, Removes the errorClass on the form and hides all error messages. [Note: Avoid using it with focusInvalid.】
19. errorElement Use the html element type to create a container for error messages. Default is written in label
20.
errorClassSet the style to define errors The style of the message.
21.
highlight Set the highlight to the form elements that have not passed the verification.
highlight: function (element, errorClass) { $(element).addClass(errorClass); $(element).fadeOut.fadeIn(); }
The above is the detailed content of Detailed explanation of the use of jQuery Validation. For more information, please follow other related articles on the PHP Chinese website!