Home > Web Front-end > JS Tutorial > jquery.validate usage guide Part 3_jquery

jquery.validate usage guide Part 3_jquery

WBOY
Release: 2016-05-16 18:24:12
Original
1102 people have browsed it
1: Customize form submission

Set submitHandler to customize form submission action

$(".selector").validate({
submitHandler: function(form ) { alert("Verification passed"); }
});

If you need to submit a form, you can call
form.submit(); or $(form).ajaxSubmit();

2: Debug mode

Set debug to true, the form will not be submitted, only checked, convenient for debugging

$(".selector" ).validate({
debug: true
})

3: Set the default value of validate

Use setDefaults to set the default value of validate. For example, by default all form validation is performed in debug mode

$.validator.setDefaults({
debug: true
})

4: Certain elements Do not validate

Set the ignore attribute to ignore certain elements Do not validate

$(".selector").validate({
ignore: "ignore"
} )

5: Verification timing

jquery.validate can easily set when the verification action is triggered

onsubmit: whether to verify when submitting

$(".selector").validate({
onsubmit: false
})

onfocusout: Validate when focus is lost (except checkboxes/radio)

$(".selector").validate({
onfocusout: false
})

onkeyup: Validate at keyup

$(".selector").validate ({
onkeyup: false
})

onclick: Validate when checkboxes and radio are clicked.

$(".selector").validate({
onclick : false
})

6: Rewrite verification rules and verification prompt information

//Rewrite max’s verification prompt information
$. validator.messages.max = jQuery.format("Your totals musn't exceed {0}!");

//Rewrite the equal method
$.validator.methods.equal = function(value , element, param) {
return value == param;
};

7: focusInvalid Whether to focus on the last action or the latest error

$(".selector").validate({
focusInvalid: false
})

8: focusCleanup

If this If the property is set to True, then when the control gains focus, remove the erroneous class definition, hide the error message, and avoid using it with focusInvalid.

$(".selector").validate({
focusCleanup: true
})

9: meta

settings meta to encapsulate validation rules

$(".selector").validate({
meta: "validate",
})
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template