2014-10-04 225 views
1

我是網絡開發新手,在這裏我知道問題非常小,但即使在兩天後,我也無法找到它。你的人可以看看這個代碼,並指出我的錯誤,請爲什麼BootstrapValidator無法正常工作?

我的代碼標識here @ JSFiddle 感謝

HTML

<form id="registerForm" action="\register" method="post"> 
    <div class="form-group"> 
     <input class="form-control" type="text" name="email" placeholder="Email"> 
    </div> 
    <div class="form-group"> 
     <input class="form-control" type="password" name="pass1" placeholder="Password"> 
    </div> 
    <div class="form-group"> 
     <input class="form-control" type="password" name="pass2" placeholder="Confirm Password"> 
    </div> 
    <button class="btn btn-primary" type="submit">Signup</button> 
</form> 

JS

$(document).ready(function() { 
    $('.registerForm').bootstrapValidator({ 
     message: 'This value is not valid', 
     feedbackIcons: { 
      valid: 'glyphicon glyphicon-ok', 
      invalid: 'glyphicon glyphicon-remove', 
      validating: 'glyphicon glyphicon-refresh' 
     }, 
     fields: { 
      email: { 
       validators: { 
        notEmpty: { 
         message: 'The email is required and cannot be empty' 
        }, 
        emailAddress: { 
         message: 'The input is not a valid email address' 
        } 
       } 
      }, 
      pass1: { 
       validators: { 
        identical: { 
         field: 'pass2', 
         message: 'The password and its confirm are not the same' 
        } 
       } 
      }, 
      pass2: { 
       validators: { 
        identical: { 
         field: 'pass1', 
         message: 'The password and its confirm are not the same' 
        } 
       } 
      } 
     } 

    }); 
}); 
+0

有什麼問題?正好 – 2014-10-04 07:40:44

+0

http://jsfiddle.net/victor_007/uw0afL1u/1/如果您將類從作品更改爲id – 2014-10-04 07:42:16

回答

0

JavaScript是綁定到類registerForm ,而不是id。在您的JavaScript代碼中將.registerForm更改爲#registerForm。

編輯: 或者添加class = 「registerForm」 到YouTube的表單元素在HTML

3

要獲取的ID使用的節點:$('#registerForm')。如果您獲得$('.registerForm'),JS將在<form>標籤中查找類registerForm

閱讀jQuery API是防止這種錯誤的好方法。 http://api.jquery.com/category/selectors/

相關問題