2013-10-26 3 views
0

방금 ​​jQuery 유효성 검사를 읽었으며 문제가 발생했습니다. 제출 버튼을 클릭해도 유효성 검사가 실행되지 않습니다. 나는 몇 시간 동안 조사를 해왔지만 불행히도 해결책을 찾지 못했습니다.내 jQuery 유효성 검사가 작동하지 않음

내 코드 :

<!DOCTYPE html> 
<html lang="en"> 
<head> 
     <title> Test </title> 

     <style> 

       body { 
         max-width: 70em; 
         margin: auto; 
         padding: 0; 
       } 

       .container { 
         max-width: 50%; 
         margin: auto auto; 
         -webkit-border-radius: 5px; 
         -moz-border-radius: 5px; 
         border-radius: 5px; 
       } 

       input, button { 
         display: block; 
         margin: 0.5em auto; 
         height: 2em; 
         width: 90%; 
       } 

       button { 
         border: 0; 
         background-color: green; 
       } 

       .text-center { 
         text-align: center; 
       } 
     </style> 

</head> 

<body> 

     <div class="container"> 
       <form method="POST" id="form"> 
         <h2 class="text-center"> Register! </h2> 
         <label> Username </label> 
         <input type="text" name="username"> 
         <label> Password </label> 
         <input type="password" name="password"> 
         <label> Password Confirmation </label> 
         <input type="password" name="password_confirmation"> 
         <label> Email </label> 
         <input type="password" name="password_confirmation"> 
         <input type="submit" value="Submit"> 
       </form> 
     </div> 

     <script src="http://code.jquery.com/jquery-1.8.3.min.js" type="text/javascript"></script> 
     <script src="http://ajax.aspnetcdn.com/ajax/jquery.validate/1.10.0/jquery.validate.js" type="text/javascript"></script> 

     <script> 

     $(document).ready(function() { 
       $("#form").validate({ 
         rules: { 
           username: { 
             required: true, 
             range: [4, 15] 
           } 

           password: { 
             required: true, 
             minlength: 8 
           } 

           email: { 
             required: true, 
             email: true 
           } 
         } 
       }); 
     }); 



     </script> 
</body> 
</html> 

JSFiddle : http://jsfiddle.net/hPmec/

+0

... – Terry

+0

그리고 자바를 보았어 야합니다. 쉼표가 없기 때문에 콘솔 로그의 오류를 스크립트하십시오. – Sparky

답변

3

당신은 스크립트 구문 오류가

$(document).ready(function() { 
    $("#form").validate({ 
     rules: { 
      username: { 
       required: true, 
       range: [4, 15] 
      }, //missing , 

      password: { 
       required: true, 
       minlength: 8 
      }, //missing , 

      email: { 
       required: true, 
       email: true 
      } 
     } 
    }); 
}); 

데모 : 당신은 각 개체 후 쉼표를 잊어 버린 Fiddle

관련 문제