是導(dǎo)入的validate.js文件不對嗎,為什么怎么弄都沒反應(yīng),是在官網(wǎng)下的jquery-validation-1.15.0呀?還是代碼寫錯了?
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>validate表單驗證</title>
<script src="js/jquery-1.12.4.min.js" type="text/javascript"></script>
<script src="js/jquery.validate.js" type="text/javascript"></script>
<style>
?? ?body
?? ?{
?? ??? ?font-size:30px;
?? ?}
?? ?label
?? ?{
?? ??? ?display:inline-block;
?? ??? ?min-width:140px;
?? ?}
?? ?#demoForm
?? ?{
?? ??? ?margin:0px auto;
?? ??? ?padding:inherit;
?? ??? ?height:100px;
?? ??? ?border:solid 1px #999;
?? ??? ?width:180px;
?? ?}
?? ?input.error
?? ?{
?? ??? ?border:solid 2px red;
?? ?}
?? ?input
?? ?{
?? ??? ?
?? ?}
?? ?
</style>
</head>
<body>
?? ?<form id="demoForm">
?? ??? ?<fieldset>
?????? ??? ?<legend>用戶登錄 </legend>
?????????? ??? ?
????????? ?
??????????????? <p>
?????????????? ??? ?<label for="username">用戶名</label>
??????????????????? <input type="text" id="username" class="username"/>
??????????????? </p>
??????????????? <p>
?????????????? ??? ?<label for="password">用戶密碼</label>
??????????????????? <input type="password" id="password" class="password"/>
??????????????? </p>? ?
??????????????? <p>
?????????????? ??? ?<input type="submit" value="登錄" />
??????????????? </p>
??????? </fieldset>
??? </form>
??? <script>
?? ??? ?$(document).ready(function(){
?? ??? ??? ?$("#demoForm").validate({
?? ??? ??? ??? ?rules:{
?? ??? ??? ??? ??? ?username:{
?? ??? ??? ??? ??? ??? ?required:true,
?? ??? ??? ??? ??? ??? ?minlength:2,
?? ??? ??? ??? ??? ??? ?maxlength:10
?? ??? ??? ??? ??? ?},
?? ??? ??? ??? ??? ?password:{
?? ??? ??? ??? ??? ??? ?required:true,
?? ??? ??? ??? ??? ??? ?minlength:2,
?? ??? ??? ??? ??? ??? ?maxlength:10
?? ??? ??? ??? ??? ?},
?? ??? ??? ??? ?}
?? ??? ??? ??? ?
?? ??? ??? ??? ?
?? ??? ??? ?});
?? ??? ?});
??? </script>
?? ?
</body>
</html>
2016-05-29
你要給input 加上name屬性<input type="text" id="username" name="username"?class="username"/>