为什么不禁用Bootstrap-Select上的属性工作?
-
21-12-2019 - |
题
我想用我的网站表单,输入和选择。我使用了 bootstrap 用于输入和 bootstrap-select for selects和 iCheck 用于复选框。问题是,iCheck无法使用Bootstrap-Select正确正常工作。
这里是jsfiddle test: http://jsfiddle.net/36xpf/
现在,尝试检查iCheck复选框,选择Bootstrap-Select将不会被禁用。然后检查标准方形复选框,将禁用选定引导程序。
我收到禁用的属性,以选择复选框aurign jquery .change()
:
$('#checkbox1').change(function(){
if (this.checked) {
$('.selectpicker').attr('disabled', false);
} else {
$('.selectpicker').attr('disabled', true);
}
});
.
我做错了什么?为什么禁用属性不适用于Bootstrap选择?
任何帮助都受到赞赏!谢谢!
解决方案
是一个插件,而不是正则复选框,您必须侦听它实际支持的事件:
$('#checkbox1').on('ifChanged', function(){
$('.selectpicker').attr('disabled', this.checked).selectpicker('refresh');
}).iCheck({
checkboxClass: 'icheckbox_flat-red',
radioClass: 'iradio_flat-red'
});
.
其他提示
$('input#checkbox1').iCheck({
checkboxClass: 'icheckbox_flat-red',
radioClass: 'iradio_flat-red'
});
$('.selectpicker').selectpicker();
$(document).on('ifChecked','#checkbox1',function(){
$('.selectpicker').prop('disabled',true);
$('.selectpicker').selectpicker('refresh');
});
$(document).on('ifUnchecked','#checkbox1',function(){
$('.selectpicker').prop('disabled',false);
$('.selectpicker').selectpicker('refresh');
});
/*standard checkbox*/
$('#checkbox2').change(function(){
if (this.checked) {
$('.standard').attr('disabled', true);
} else {
$('.standard').attr('disabled', false);
}
});
.
使用此JS代码
不隶属于 StackOverflow