3.快速入门
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>jQuery validation plug-in - main demo</title>
<link rel="stylesheet" href="css/screen.css">
<script src="../lib/jquery.js"></script>
<script src="../dist/jquery.validate.js"></script>
<script>
$().ready(function() {
// validate signup form on keyup and submit
$("#signupForm").validate({
//需要验证的表单项
rules:{
firstname:{
required:true,
minlength:2
}
},
//定义校验失败的提示信息
messages:{
firstname:{
required:"你没有填写数据",
minlength:"你的长度不够"
}
}
});
});
</script>
</head>
<body>
<div id="main">
<form class="cmxform" id="signupForm" method="get" action="">
<fieldset>
<legend>Validating a complete form</legend>
<p>
<label for="firstname">Firstname</label>
<input id="firstname" name="firstname" type="text">
</p>
<p>
<input class="submit" type="submit" value="Submit">
</p>
</fieldset>
</form>
</div>
</body>
</html>