如何通过ickeck复选框启用/禁用引导程序选择器 [英] How to enable/disable bootstrap selectpicker by ickeck checkbox

查看:189
本文介绍了如何通过ickeck复选框启用/禁用引导程序选择器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

checkbox旁边有selectpicker.我想如果选中复选框,将启用selectpicker,如果未选中,则将禁用selectpicker. 我写的这行不通(这是小提琴):

There are selectpicker beside checkbox. I want if checkbox is checked, selectpicker will be enable, if unchecked, selectpicker will be disable. I wrote this which was not working ( Here is the fiddle ):

$('.checkBox').on('ifChecked', function(event) {
    $(this).parents('.clearfix').find('.selectpicker').removeAttr('disabled');

});
$('.checkBox').on('ifUnchecked', function(event) {
    $(this).parents('.clearfix').find('.selectpicker').attr('disabled');
});

推荐答案

更改完成后,您应该刷新选择器

You should refresh the selectpicker once the change is done

这是一个有效的小提琴

刷新UI的代码是

$('.selectpicker').selectpicker('refresh');

有关更多信息,请参见 DOCS

for more information refer the DOCS

我发现的另一个错误是,要禁用,您必须使用

One more mistake i have found is, to disable you have to use

attr('disabled',true)

不是

attr('disabled')

这篇关于如何通过ickeck复选框启用/禁用引导程序选择器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆