尝试验证引导复选框时,jQuery验证错误 [英] Jquery validation Error when trying to validate a bootstrap checkbox
本文介绍了尝试验证引导复选框时,jQuery验证错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在使用Jquery验证插件,一切正常,但是当我尝试验证复选框时出现错误:
I'm using Jquery validation plugin, everything work fine but when i try to validate the check box i got an error:
TypeError: b is undefined
这是我的引导复选框脚本:
here's my bootstrap checkbox script:
<div class="col-xs-8">
<div class="checkbox icheck">
<label>
<input type="checkbox" required> I agree to the <a href="#">terms</a>
</label>
</div>
</div>
这是我使用的jquery验证:
and here's the jquery validation that i used:
$("#formRegister").validate({
errorElement: "span",
errorClass: "help-block",
highlight: function (element, errorClass, validClass) {
// Only validation controls
if (!$(element).hasClass('novalidation')) {
$(element).closest('.form-group').removeClass('has-success').addClass('has-error');
}
},
unhighlight: function (element, errorClass, validClass) {
// Only validation controls
if (!$(element).hasClass('novalidation')) {
$(element).closest('.form-group').removeClass('has-error').addClass('has-success');
}
},
errorPlacement: function (error, element) {
if (element.parent('.input-group').length) {
error.insertAfter(element.parent());
}
else if (element.prop('type') === 'radio' && element.parent('.radio-inline').length) {
error.insertAfter(element.parent().parent());
}
else if (element.prop('type') === 'checkbox' || element.prop('type') === 'radio') {
error.appendTo(element.parent().parent());
}
else {
error.insertAfter(element);
}
}
推荐答案
必需的输入也必须具有name
.没有名称,浏览器将不会提交,因此也不需要
A required input also must have a name
. Without a name it won't be submitted by browser and therefore can't also be required
<input name="terms" type="checkbox" required>
这篇关于尝试验证引导复选框时,jQuery验证错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文