2 3

Detailed explanation of the use of jQuery Validation

PHP中文网
Release: 2017-06-21 13:33:23
Original
2016 people have browsed it

jQuery Validation Framework:

Basic html code:

1    2  3 40 41 42 html:43 
44 45

46 47 48

49 50

51 52 53

54 55

56   
Copy after login

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("校验全部通过!") },
Copy after login

16.invalidHandler When a form that fails validation is submitted, you can Handle some stuff in that callback function.

// 校验不通过              invalidHandler: function () { alert("no") },
Copy after login

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(); }
Copy after login

The above are what I have come into contact with, and there are many more about
jQuery validation framework
. Those who are interested can check the API of jQuery.validate.js.

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!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!