jquery.validata.js plug-in collection, everything you want is here

巴扎黑
Release: 2017-06-23 11:03:30
Original
1253 people have browsed it

Combined with the above, today I will write about how to use validate.

validate() validates the selected form.

validate method returns a Validator object. The Validator object has many methods that can be used to trigger validators or change the contents of the form.

Validate() options:

submitHandler: A function that is run after passing verification. The form submission function must be added to it, otherwise the form will not be submitted.

$("#demoForm").validate({ submitHandler:function() { alert('校验全部通过!') }})

ignore:忽略某个元素不校验
ignore:'#pass2'//忽略某个元素不校验
rules:自定义规则,key:value 的形式,key 是要验证的元素,value 可以是字符串或对象。
Copy after login
$("#demoForm").validate({ rules:{ name:"required", email:{ required:true, email:true}}})
messages:自定义的提示信息,key:value 的形式,key 是要验证的元素,value 可以是字符串或函数。
Copy after login
$("#demoForm").validate({ rules:{ name:"required", email:{ required:true, email:true}}, messages:{ name:"Name不能为空", email:{ required:"E-mail不能为空", email:"E-mail地址不正确"}}})
OnSubmit:类型 Boolean,默认 true,指定是否提交时验证。
Copy after login
$("#demoForm").validate({ onsubmit:false })
Copy after login

Copy after login
onfocusout:类型 Boolean,默认 true,指定是否在获取焦点时验证。
Copy after login

Copy after login
$("#demoForm").validate({ onfocusout:false })
Copy after login

onkeyup:类型 Boolean,默认 true,指定是否在敲击键盘时验证。
Copy after login
$("#demoForm").validate({ onkeyup:false })
Copy after login

onclick:类型 Boolean,默认 true,指定是否在鼠标点击时验证(一般验证 checkbox、radiobox)。
Copy after login
$("#demoForm")
Copy after login
Copy after login
Copy after login
Copy after login
).validate({ onclick:false })
Copy after login

focusInvalid:类型 Boolean,默认 true。提交表单后,未通过验证的表单(第一个或提交之前获得焦点的未通过验证的表单)会获得焦点。
Copy after login
$("#demoForm")
Copy after login
Copy after login
Copy after login
Copy after login
.validate({ focusInvalid:false })
Copy after login

focusCleanup:类型 Boolean,默认 false。当未通过验证的元素获得焦点时,移除错误提示(避免和 focusInvalid 一起使用)
Copy after login
$("#demoForm")
Copy after login
Copy after login
Copy after login
Copy after login
.validate({ focusCleanup:true })
Copy after login

errorClass:类型 String,默认 "error"。指定错误提示的 css 类名,可以自定义错误提示的样式。
Copy after login
$("#demoForm")
Copy after login
Copy after login
Copy after login
Copy after login
.validate({ errorClass:"invalid" })
Copy after login

errorElement:类型 String,默认 "label"。指定使用什么标签标记错误。
Copy after login
r

The above is the detailed content of jquery.validata.js plug-in collection, everything you want is here. 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!