[py]jquery表单验证插件初探

jquery表单验证插件初探

参考:
http://www.runoob.com/jquery/jquery-plugin-validate.html
http://www.cnblogs.com/liuhongfeng/p/5134648.html

使用jquery.validate.min.js插件

    <script src="http://static.runoob.com/assets/jquery-validation-1.14.0/lib/jquery.js"></script>
    <script src="http://static.runoob.com/assets/jquery-validation-1.14.0/dist/jquery.validate.min.js"></script>
    <script src="http://static.runoob.com/assets/jquery-validation-1.14.0/dist/localization/messages_zh.js"></script>

注意: messages_zh.js这个好像是当输入不标准时候弹出的warning信息.

form表单调用js

效果:

js完整代码

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title>jQuery PlugIn -一个简单带验证例子</title>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
    <script src="http://static.runoob.com/assets/jquery-validation-1.14.0/lib/jquery.js"></script>
    <script src="http://static.runoob.com/assets/jquery-validation-1.14.0/dist/jquery.validate.min.js"></script>
    <script src="http://static.runoob.com/assets/jquery-validation-1.14.0/dist/localization/messages_zh.js"></script>
    <style type="text/css">
    * { font-family: Verdana; font-size:13px; }
    input[type='text']{width:200px;}
    textarea{width:155px;}
    label { width: 10em; float: left; }
    label.error { float: none; color: red; padding-left: .5em; vertical-align: top; }
    </style>
    <script>
    $(document).ready(function(){
        $("#commentForm").validate();
    });
    </script>
</head>
<body>

 <form id="commentForm" method="get" action="" >
 <fieldset>
   <legend>表单验证</legend>
   <p><label>Name</label><input  name="name" class="required" maxlength="4" minlength="2"  /></p>
   <p><label >E-Mail</label><input  name="email" class="required email" /></p>
   <p><label >URL</label><input  name="url" class="url"/></p>
   <p><label>text</label><textarea name="text" cols="22"  class="required"></textarea></p>
   <p><input class="submit" type="submit" value="提交"/></p>
 </fieldset>
 </form>

</body>
</html>
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值