我是Web开发的新手,在这里我知道这个问题很小,但是即使过了两天,我仍然找不到它。大家可以看看这段代码并指出我的错误吗?
我的代码ID 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'
}
}
}
}
});
});
最佳答案
要通过ID获取节点,请使用:$('#registerForm')
。如果通过$('.registerForm')
获取,则JS将在registerForm
标记中查找类<form>
。
阅读jQuery API是防止此类错误的好方法。
http://api.jquery.com/category/selectors/