<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>jQuery Validation 插件</title>
<link rel="stylesheet" href="style.css">>
</head>
<body>
<form id="demoForm">
<fieldset>
<legend>用户登录</legend>
<p>
<label for="username">用户名</label>
<input type="text" name="username1" id="username"/>
</p>
<p>
<label for="password">密码</label>
<input type="password" id="password" name="password1">
</p>
<p>
<label for="confirm-password">确认密码</label>
<input type="password" id="confirm-password" name="confirm-password1">
</p>
<p>
<input type="submit" name="登录"/>
</p>
</fieldset>
</form>
<script src="file:///C|/Users/Administrator/Desktop/jQuery实验/用户登录/vendor/jquery-1.10.0.js"></script>
<script src="file:///C|/Users/Administrator/Desktop/jQuery实验/用户登录/vendor/jquery.validate-1.13.1.js"></script>
<script>
$(document).ready(function(){
$("#demoForm").validate({
debug:true,
rules:{
username1:{
required:true,
//minlength:2,
//maxlength:10,
//rangelength:[2,10],
//digits:true
//远程校验
/*remote:{
url:"remote.json",
type:"post",
data:{
loginTime:function(){
return +new Date;
}
}
}*/
},
password1:{
required:true,
minlength:2,
maxlength:16
},
//确认密码
"confirm-password1":{
equalTo:"#password1"
}
},
//信息提示
messages:{
username1:{
required:"必需填写用户名",
minlength:"用户名最少为2位",
maxlength:"用户名最多为10位",
remote:"用户名不存在",
rangelength:"用户名应该在2-10位"
},
password1:{
required:"必需填写密码",
minlength:"密码最少为2位",
maxlength:"密码最多为16位"
}
"confirm-password1":{
equalTo:"两次输入的密码不一致"
}
}
});
});
</script>
</body>
</html>
password1:{ required:"必需填写密码", minlength:"密码最少为2位", maxlength:"密码最多为16位" }, //上一行缺少了一个逗号,应该就只有这个错误,其他的验证没有问题。 "confirm-password1":{ equalTo:"两次输入的密码不一致" }