首頁 > web前端 > js教程 > 主體

jquery.validata.js 外掛程式集合,想要的都在這裡

巴扎黑
發布: 2017-06-23 11:03:30
原創
1325 人瀏覽過

結合上面的,今天就寫validate的使用方法。

validate()驗證所選的form。

validate 方法傳回一個 Validator 物件。 Validator 物件有很多方法可以用來引發校驗程式或改變 form 的內容。

validate()的可選項:

submitHandler:經過驗證後執行的函數,裡面要加上表單提交的函數,否則表單不會提交。

<span class="pln">$<span class="pun">(<span class="str">"#demoForm"<span class="pun">).<span class="pln">validate<span class="pun">({<span class="pln">
	submitHandler<span class="pun">:<span class="kwd">function<span class="pun">(<span class="pln"><span class="pun">)<span class="pln"> <span class="pun">{<span class="pln"><span class="pun"><span class="pln"><span class="pun"><span class="pln"><span class="pun"><span class="pln">             alert(&#39;校验全部通过!&#39;)	<span class="pun">}<span class="pln"><span class="pun">})<br/><br/><span style="font-family: "Microsoft YaHei"; font-size: 16px">ignore:忽略某个元素不校验<br/><span style="font-size: 14px">ignore:&#39;#pass2&#39;//忽略某个元素不校验<br/><span style="font-size: 16px">rules:自定义规则,key:value 的形式,key 是要验证的元素,value 可以是字符串或对象。<br/></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span>
登入後複製
<span class="pln">$<span class="pun">(<span class="str">"#demoForm"<span class="pun">).<span class="pln">validate<span class="pun">({<span class="pln">
	rules<span class="pun">:{<span class="pln">
		name<span class="pun">:<span class="str">"required"<span class="pun">,<span class="pln">
		email<span class="pun">:{<span class="pln">
			required<span class="pun">:<span class="kwd">true<span class="pun">,<span class="pln">
			email<span class="pun">:<span class="kwd">true<span class="pln"><span class="pun">}<span class="pln"><span class="pun">}<span class="pln"><span class="pun">})<br/><span style="font-family: "Microsoft YaHei"; font-size: 16px">messages:自定义的提示信息,key:value 的形式,key 是要验证的元素,value 可以是字符串或函数。<br/></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span>
登入後複製
<span class="pln">$<span class="pun">(<span class="str">"#demoForm"<span class="pun">).<span class="pln">validate<span class="pun">({<span class="pln">
	rules<span class="pun">:{<span class="pln">
		name<span class="pun">:<span class="str">"required"<span class="pun">,<span class="pln">
		email<span class="pun">:{<span class="pln">
			required<span class="pun">:<span class="kwd">true<span class="pun">,<span class="pln">
			email<span class="pun">:<span class="kwd">true<span class="pln"><span class="pun">}<span class="pln"><span class="pun">},<span class="pln">
	messages<span class="pun">:{<span class="pln">
		name<span class="pun">:<span class="str">"Name不能为空"<span class="pun">,<span class="pln">
		email<span class="pun">:{<span class="pln">       
			required<span class="pun">:<span class="str">"E-mail不能为空"<span class="pun">,<span class="pln">
			email<span class="pun">:<span class="str">"E-mail地址不正确"<span class="pln"><span class="pun">}<span class="pln"><span class="pun">}<span class="pln"><span class="pun">})<br/><span style="font-family: "Microsoft YaHei"; font-size: 16px">OnSubmit:类型 Boolean,默认 true,指定是否提交时验证。<br/></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span>
登入後複製
$("#demoForm").validate({ onsubmit:false })
登入後複製
 <br/>
登入後複製
<span class="pln"><span class="pun"><span class="str"><span class="pun"><span class="pln"><span class="pun"><span class="pln"><span class="pun"><span class="pln"><span class="pun"><span class="str"><span class="pun"><span class="pln"><span class="pun"><span class="pln"><span class="pun"><span class="kwd"><span class="pun"><span class="pln"><span class="pun"><span class="kwd"><span class="pln"><span class="pun"><span class="pln"><span class="pun"><span class="pln"><span class="pun"><span style="font-family: "Microsoft YaHei"; font-size: 16px">onfocusout:类型 Boolean,默认 true,指定是否在获取焦点时验证。</span><br/></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span>
登入後複製
<br/>
登入後複製
$("#demoForm").validate({ onfocusout:false })
登入後複製
<br/>onkeyup:类型 Boolean,默认 true,指定是否在敲击键盘时验证。<br/>
登入後複製
$("#demoForm").validate({ onkeyup:false })
登入後複製
<br/>onclick:类型 Boolean,默认 true,指定是否在鼠标点击时验证(一般验证 checkbox、radiobox)。<br/>
登入後複製
$("#demoForm")
登入後複製
登入後複製
登入後複製
登入後複製
).validate({ onclick:false })
登入後複製
<br/>focusInvalid:类型 Boolean,默认 true。提交表单后,未通过验证的表单(第一个或提交之前获得焦点的未通过验证的表单)会获得焦点。<br/>
登入後複製
$("#demoForm")
登入後複製
登入後複製
登入後複製
登入後複製
.validate({ focusInvalid:false })
登入後複製
<br/>focusCleanup:类型 Boolean,默认 false。当未通过验证的元素获得焦点时,移除错误提示(避免和 focusInvalid 一起使用)<br/>
登入後複製
$("#demoForm")
登入後複製
登入後複製
登入後複製
登入後複製
.validate({ focusCleanup:true })
登入後複製
<br/>errorClass:类型 String,默认 "error"。指定错误提示的 css 类名,可以自定义错误提示的样式。<br/>
登入後複製
$("#demoForm")
登入後複製
登入後複製
登入後複製
登入後複製
.validate({ errorClass:"invalid" })
登入後複製
<br/>errorElement:类型 String,默认 "label"。指定使用什么标签标记错误。<br/>
登入後複製

以上是jquery.validata.js 外掛程式集合,想要的都在這裡的詳細內容。更多資訊請關注PHP中文網其他相關文章!

相關標籤:
來源:php.cn
本網站聲明
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn
熱門教學
更多>
最新下載
更多>
網站特效
網站源碼
網站素材
前端模板