jQuery Validate设置onkeyup验证的实例代码
jQuery Validate 插件为表单提供了强大的验证功能,让客户端表单验证变得更简单,同时提供了大量的定制选项,满足应用程序各种需求。下面给大家分享一段jquery validate 设置onkeyup验证的代码,具体代码如下所示:
代码如下所示:
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>菜鸟教程(runoob.com)</title> <script src="//static.runoob.com/assets/jquery-validation-1.14.0/lib/jquery.js"></script> <script src="//static.runoob.com/assets/jquery-validation-1.14.0/dist/jquery.validate.min.js"></script> <script src="//static.runoob.com/assets/jquery-validation-1.14.0/dist/localization/messages_zh.js"></script> <script> $.validator.setDefaults({ submitHandler: function() { alert("提交事件!"); } }); $().ready(function() { $("#commentForm").validate({ onkeyup: function(element) { $(element).valid(); } }); }); </script> <style> .error{ color:red; } </style> </head> <body> <form class="cmxform" id="commentForm" method="get" action=""> <fieldset> <legend>输入您的名字,邮箱,URL,备注。</legend> <p> <label for="cname">Name (必需, 最小两个字母)</label> <input id="cname" name="name" minlength="2" type="text" required> </p> <p> <label for="cemail">E-Mail (必需)</label> <input id="cemail" type="email" name="email" required> </p> <p> <label for="curl">URL (可选)</label> <input id="curl" type="url" name="url"> </p> <p> <label for="ccomment">备注 (必需)</label> <textarea id="ccomment" name="comment" required></textarea> </p> <p> <input class="submit" type="submit" value="Submit"> </p> </fieldset> </form> </body> </html>
相关阅读:
利用jQuery.Validate异步验证用户名是否存在(推荐)
JQuery validate插件Remote用法大全
jQuery easyui的validatebox校验规则扩展及easyui校验框validatebox用法
jquery.validate 自定义验证方法及validate相关参数
相关推荐
tztzyzyz 2020-07-20
rumengqiang 2012-11-23
云海梦尘 2016-09-01
jiaojiao0 2015-01-28
YOKOELEMENT 2014-12-17
pengpengflyjhp 2020-05-31
tanyhuan 2020-04-18
ELEMENTS爱乐小超 2020-01-17
81463166 2020-01-09
摄郎Elements 2014-04-10
zangdaiyang 2019-10-28
eroshn 2019-10-19