Rumah > hujung hadapan web > tutorial js > jquery.validata.js 插件集合,想要的都在这里

jquery.validata.js 插件集合,想要的都在这里

巴扎黑
Lepaskan: 2017-06-23 11:03:30
asal
1343 orang telah melayarinya

结合上面的,今天写一下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>
Salin selepas log masuk
<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>
Salin selepas log masuk
<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>
Salin selepas log masuk
$("#demoForm").validate({ onsubmit:false })
Salin selepas log masuk
 <br/>
Salin selepas log masuk
<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>
Salin selepas log masuk
<br/>
Salin selepas log masuk
$("#demoForm").validate({ onfocusout:false })
Salin selepas log masuk
<br/>onkeyup:类型 Boolean,默认 true,指定是否在敲击键盘时验证。<br/>
Salin selepas log masuk
$("#demoForm").validate({ onkeyup:false })
Salin selepas log masuk
<br/>onclick:类型 Boolean,默认 true,指定是否在鼠标点击时验证(一般验证 checkbox、radiobox)。<br/>
Salin selepas log masuk
$("#demoForm")
Salin selepas log masuk
Salin selepas log masuk
Salin selepas log masuk
Salin selepas log masuk
).validate({ onclick:false })
Salin selepas log masuk
<br/>focusInvalid:类型 Boolean,默认 true。提交表单后,未通过验证的表单(第一个或提交之前获得焦点的未通过验证的表单)会获得焦点。<br/>
Salin selepas log masuk
$("#demoForm")
Salin selepas log masuk
Salin selepas log masuk
Salin selepas log masuk
Salin selepas log masuk
.validate({ focusInvalid:false })
Salin selepas log masuk
<br/>focusCleanup:类型 Boolean,默认 false。当未通过验证的元素获得焦点时,移除错误提示(避免和 focusInvalid 一起使用)<br/>
Salin selepas log masuk
$("#demoForm")
Salin selepas log masuk
Salin selepas log masuk
Salin selepas log masuk
Salin selepas log masuk
.validate({ focusCleanup:true })
Salin selepas log masuk
<br/>errorClass:类型 String,默认 "error"。指定错误提示的 css 类名,可以自定义错误提示的样式。<br/>
Salin selepas log masuk
$("#demoForm")
Salin selepas log masuk
Salin selepas log masuk
Salin selepas log masuk
Salin selepas log masuk
.validate({ errorClass:"invalid" })
Salin selepas log masuk
<br/>errorElement:类型 String,默认 "label"。指定使用什么标签标记错误。<br/>
Salin selepas log masuk
$(".selector").validate
   errorElement:"em"})
Salin selepas log masuk
<br/>highlight:可以给未通过验证的元素加效果、闪烁等。<br/><br/>
Salin selepas log masuk

Atas ialah kandungan terperinci jquery.validata.js 插件集合,想要的都在这里. Untuk maklumat lanjut, sila ikut artikel berkaitan lain di laman web China PHP!

Label berkaitan:
sumber:php.cn
Kenyataan Laman Web ini
Kandungan artikel ini disumbangkan secara sukarela oleh netizen, dan hak cipta adalah milik pengarang asal. Laman web ini tidak memikul tanggungjawab undang-undang yang sepadan. Jika anda menemui sebarang kandungan yang disyaki plagiarisme atau pelanggaran, sila hubungi admin@php.cn
Tutorial Popular
Lagi>
Muat turun terkini
Lagi>
kesan web
Kod sumber laman web
Bahan laman web
Templat hujung hadapan