jQuery.validate验证时用的是Form输入表单的name属性

例如:

[html]  view plain  copy
  1. <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">  
  2. <html>  
  3. <head>  
  4. <title>test</title>  
  5. <meta http-equiv="Content-Type" content="text/html;charset=utf-8" />  
  6. <meta http-equiv="Cache-Control" content="no-store" />  
  7. <meta http-equiv="Pragma" content="no-cache" />  
  8. <meta http-equiv="Expires" content="0" />  
  9.    
  10. <link href="/static/jquery-easyui/1.2.6/themes/default/easyui.css"  
  11.     type="text/css" rel="stylesheet">  
  12. <link href="/static/jquery-easyui/1.2.6/themes/icon.css"  
  13.     type="text/css" rel="stylesheet">  
  14. <link href="/static/style/demo.css" type="text/css"  
  15.     rel="stylesheet">  
  16. <link href="/static/jquery-validation/1.9.0/milk.css"  
  17.     type="text/css" rel="stylesheet" />  
  18.    
  19. <script src="/static/jquery/1.7.2/jquery.min.js"  
  20.     type="text/javascript"></script>  
  21. <script src="/static/jquery-easyui/1.2.6/jquery.easyui.min.js"  
  22.     type="text/javascript"></script>  
  23. <script  
  24.     src="/static/jquery-validation/1.9.0/jquery.validate.min.js"  
  25.     type="text/javascript"></script>  
  26. <script src="/static/jquery-validation/1.9.0/messages_cn.js"  
  27.     type="text/javascript"></script>  
  28.    
  29. <script>    
  30.   
  31. $(document).ready(function() {  
  32.     $("#inputForm").validate({  
  33.         rules : {  
  34.                 name:{  
  35.                     required:true,  
  36.                     minlength:"3"     
  37.                 },    
  38.                 password:{  
  39.                     minlength:"3"     
  40.                 },    
  41.                 passwordConfirm:{  
  42.                     equalTo : "#password"  
  43.                 },  
  44.                 email:{  
  45.                     required:true,  
  46.                     email:true    
  47.                 }         
  48.         },  
  49.         messages : {  
  50.   
  51.         }  
  52.     });  
  53. });  
  54. </script>  
  55. <title>PLMII:用户管理</title>  
  56. </head>  
  57. <body>  
  58.     <form id="inputForm" action="user!save.action" method="post">   
  59.     <table align="left">  
  60.         <tr align="left">  
  61.         <td nowrap><label for="name" class="field">姓名:</label></td>  
  62.         <td><input  type="text" id="name" name="name" size="25" value=""/></td>     
  63.         <td nowrap><label for="email" class="field">邮箱:</label></td>  
  64.         <td><input  type="text" id="email" name="email"    size="25" value=""/></td>    
  65.         </tr>  
  66.             <tr align="left">                   
  67.         <td nowrap><label for="password" class="field">密码:</label></td>  
  68.         <td><input type="password" id="password" name="password" size="26" value="" /></td>  
  69.         <td nowrap><label for="passwordConfirm" class="field">确认密码:</label></td>  
  70.         <td><input type="password" id="passwordConfirm" size="26" value="" /></td>                      
  71.        </tr>  
  72.            <tr>  
  73.                <td colspan=4 align="center">  
  74.                    <a href="#"class="easyui-linkbutton" iconCls="icon-ok"onclick='$("#inputForm").submit()'>提交</a>   
  75.                    <a href="#" class="easyui-linkbutton" iconCls="icon-cancel"onclick="history.back(-1)">取消</a>  
  76.                </td>  
  77.            </tr>  
  78.        </table>  
  79.     </form>  
  80. </body>  
  81. </html>  

 
在这段代码中,不会验证两个密码是否相同,因为确认密码输入框只定义了其id,而未定义其name,将其name加上,则验证正常。 

[html]  view plain  copy
  1. <tr align="left">                   
  2.     <td nowrap><label for="password" class="field">password:</label></td>  
  3.     <td><input type="password" id="password" name="password" size="26" value="" /></td>  
  4.     <td nowrap><label for="passwordConfirm" class="field">确认password:</label></td>  
  5.     <td><input type="password" id="passwordConfirm" name="passwordConfirm" size="26" value="" /></td>                   
  6. </tr>  
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值