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

例如:

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>test</title>
<meta http-equiv="Content-Type" content="text/html;charset=utf-8" />
<meta http-equiv="Cache-Control" content="no-store" />
<meta http-equiv="Pragma" content="no-cache" />
<meta http-equiv="Expires" content="0" />
 
<link href="/static/jquery-easyui/1.2.6/themes/default/easyui.css"
	type="text/css" rel="stylesheet">
<link href="/static/jquery-easyui/1.2.6/themes/icon.css"
	type="text/css" rel="stylesheet">
<link href="/static/style/demo.css" type="text/css"
	rel="stylesheet">
<link href="/static/jquery-validation/1.9.0/milk.css"
	type="text/css" rel="stylesheet" />
 
<script src="/static/jquery/1.7.2/jquery.min.js"
	type="text/javascript"></script>
<script src="/static/jquery-easyui/1.2.6/jquery.easyui.min.js"
	type="text/javascript"></script>
<script
	src="/static/jquery-validation/1.9.0/jquery.validate.min.js"
	type="text/javascript"></script>
<script src="/static/jquery-validation/1.9.0/messages_cn.js"
	type="text/javascript"></script>
 
<script>	

$(document).ready(function() {
	$("#inputForm").validate({
		rules : {
				name:{
					required:true,
					minlength:"3"	
				},	
				password:{
					minlength:"3"	
				},	
				passwordConfirm:{
					equalTo : "#password"
				},
				email:{
					required:true,
					email:true	
				}		
		},
		messages : {

		}
	});
});
</script>
<title>PLMII:用户管理</title>
</head>
<body>
    <form id="inputForm" action="user!save.action" method="post">	
	<table align="left">
	    <tr align="left">
		<td nowrap><label for="name" class="field">姓名:</label></td>
		<td><input  type="text" id="name" name="name" size="25" value=""/></td>	
		<td nowrap><label for="email" class="field">邮箱:</label></td>
		<td><input  type="text" id="email" name="email"	size="25" value=""/></td>	
	    </tr>
            <tr align="left">					
		<td nowrap><label for="password" class="field">密码:</label></td>
		<td><input type="password" id="password" name="password" size="26" value="" /></td>
		<td nowrap><label for="passwordConfirm" class="field">确认密码:</label></td>
		<td><input type="password" id="passwordConfirm" size="26" value="" /></td>					
	   </tr>
           <tr>
               <td colspan=4 align="center">
                   <a href="#"class="easyui-linkbutton" iconCls="icon-ok"οnclick='$("#inputForm").submit()'>提交</a> 
                   <a href="#" class="easyui-linkbutton" iconCls="icon-cancel"οnclick="history.back(-1)">取消</a>
               </td>
           </tr>
       </table>
    </form>
</body>
</html>

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

<tr align="left">					
    <td nowrap><label for="password" class="field">password:</label></td>
    <td><input type="password" id="password" name="password" size="26" value="" /></td>
    <td nowrap><label for="passwordConfirm" class="field">确认password:</label></td>
    <td><input type="password" id="passwordConfirm" name="passwordConfirm" size="26" value="" /></td>					
</tr>




评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值