twitter-bootstrap 为什么不在 Bootstrap-select 上禁用属性工作?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/20030719/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-21 19:14:04  来源:igfitidea点击:

Why doesn't disable attribute work on Bootstrap-select?

jquerytwitter-bootstrapicheckbootstrap-select

提问by Mustapha Aoussar

I want to style my website forms, inputs and selects. I used Bootstrapfor the inputs and Bootstrap-selectfor selects and iCheckfor checkboxes. The problem is that iCheck does not work correctly with Bootstrap-select.

我想设计我的网站表单、输入和选择。我使用Bootstrap作为输入,Bootstrap-select用于选择,iCheck用于复选框。问题是 iCheck 不能与 Bootstrap-select 一起正常工作。

Here is jsFiddle test: http://jsfiddle.net/36Xpf/

这是 jsFiddle 测试:http: //jsfiddle.net/36Xpf/

Now, try to check the iCheck checkbox, the select of bootstrap-select will not be disabled. Then check the standard square checkbox, the select of bootstrap will be disabled.

现在,尝试勾选 iCheck 复选框,bootstrap-select 的选择不会被禁用。然后选中标准方块复选框,引导程序的选择将被禁用。

I get the attribute disalbled to select if a checkbox is checked usign jQuery .change():

我禁用了属性以选择是否使用 jQuery 选中复选框.change()

$('#checkbox1').change(function(){
  if (this.checked) {
    $('.selectpicker').attr('disabled', false);
  } else {
    $('.selectpicker').attr('disabled', true);
  }                   
});

What did I do wrong? Why the disabled attribute doesn't work on bootstrap select?
Any help is appreciated! Thank you!

我做错了什么?为什么禁用属性在引导选择上不起作用?
任何帮助表示赞赏!谢谢!

回答by adeneo

It's a plugin, not a regular checkbox, you have to listen for events that it actually supports :

这是一个插件,而不是常规复选框,您必须监听它实际支持的事件:

$('#checkbox1').on('ifChanged', function(){
    $('.selectpicker').attr('disabled', this.checked).selectpicker('refresh');
}).iCheck({
    checkboxClass: 'icheckbox_flat-red',
    radioClass: 'iradio_flat-red' 
});

FIDDLE

小提琴

回答by Alexey Dmitriev

    $('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);
  }                   
});

use this js code

使用这个js代码