gpt4 book ai didi

jquery - Bootstrap 3 验证

转载 作者:行者123 更新时间:2023-12-01 07:13:33 25 4
gpt4 key购买 nike

我想我几乎可以让 Bootstrap 验证工作了,但它似乎有问题或者我遗漏了一些东西。使用输入组时,如何使图标显示在文本字段中。另一个问题是当它出错并且用户修复它时,x 图标仍然存在而不是复选框。

JSFiddle

$('form').validate({
rules: {
field1: {
minlength: 3,
maxlength: 15,
required: true
},
field2: {
minlength: 3,
maxlength: 15,
required: true
}
},
highlight: function(element) {
$(element).closest('.form-group').removeClass('has-success').addClass('has-error')
$(element).next('span').removeClass('glyphicon-ok').addClass('glyphicon-remove');
},
unhighlight: function(element) {
$(element).closest('.form-group').removeClass('has-error').addClass('has-success')
$(element).next('span').removeClass('glyphicon-remove').addClass('glyphicon-ok');
},
//errorElement: 'span',
errorClass: 'help-block',
errorPlacement: function(error, element) {
if(element.parent('.input-group').length) {
error.insertAfter(element.parent());
} else {
error.insertAfter(element);
}
}
});

最佳答案

问题是,下一个兄弟可能是错误消息标签而不是反馈

$('form').validate({
rules: {
field1: {
minlength: 3,
maxlength: 15,
required: true
},
field2: {
minlength: 3,
maxlength: 15,
required: true
}
},
highlight: function (element) {
$(element).closest('.form-group').removeClass('has-success').addClass('has-error')
$(element).parent().find('.form-control-feedback').removeClass('glyphicon-ok').addClass('glyphicon-remove');
},
unhighlight: function (element) {
$(element).closest('.form-group').removeClass('has-error').addClass('has-success');
$(element).parent().find('.form-control-feedback').removeClass('glyphicon-remove').addClass('glyphicon-ok');
},
//errorElement: 'span',
errorClass: 'help-block',
errorPlacement: function (error, element) {
if (element.parent('.input-group').length) {
error.insertAfter(element.parent());
} else {
error.insertAfter(element);
}
}
});

演示:Fiddle

关于jquery - Bootstrap 3 验证,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22547727/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com