为什么BootstrapValidator无法正常工作?
问题描述:
我是网络开发新手,在这里我知道问题非常小,但即使在两天后,我也无法找到它。你的人可以看看这个代码,并指出我的错误,请为什么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'
}
}
}
}
});
});
答
JavaScript是绑定到类registerForm ,而不是id。在您的JavaScript代码中将.registerForm更改为#registerForm。
编辑: 或者添加class = “registerForm” 到YouTube的表单元素在HTML
答
要获取的ID使用的节点:$('#registerForm')
。如果您获得$('.registerForm')
,JS将在<form>
标签中查找类registerForm
。
阅读jQuery API是防止这种错误的好方法。 http://api.jquery.com/category/selectors/
有什么问题?正好 – 2014-10-04 07:40:44
http://jsfiddle.net/victor_007/uw0afL1u/1/如果您将类从作品更改为id – 2014-10-04 07:42:16