无法实现自动校验
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title></title>
<style>
*{ margin: 0; padding: 0;}
fieldset {
margin: 100px auto;
height: 200px;
width: 300px;
}
</style>
<script src="jquery-1.11.1.min.js"></script>
<script src="jquery.validate-1.13.1.js"></script>
<script>
$(function(){
$("#formDemo").validate({
rules:{
username:{
require:true,
minlength:2,
maxlength:10
},
password:{
require:true,
minlength:2,
maxlength:16
}
},
message:{
username:{
require:"必须填写用户名",
minlength:"用户名最少为2位",
maxlength:"用户名最大为10位"
},
password:{
require:"必须填写密码",
minlength:"密码最少为2位",
maxlength:"密码最大为16为"
}
}
});
});
</script>
</head>
<body>
<form action="" id="formDemo">
<fieldset>
<legend>用户登录</legend>
<p><label for="username">用户名:</label><input type="text" name="username" id="username"/></p><br>
<p><label for="password">密码:</label><input type="password" name="password" id="password"/></p><br/>
<input type="submit" value="提交"/>
</fieldset>
</form>
</body>
</html>