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"onclick='$("#inputForm").submit()'>提交</a> 
                   <a href="#" class="easyui-linkbutton" iconCls="icon-cancel"onclick="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>




你可能感兴趣的:(html,function,Class,action,email,stylesheet)