twitter-bootstrap Bootstrap 启用/禁用动态选择

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/16679171/
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 17:11:10  来源:igfitidea点击:

Bootstrap Enable/Disable Chosen Select Dynamically

jquerytwitter-bootstrapjquery-chosen

提问by Guest

Does anyone know how I can dynamically enable/disable a Bootstrap Chosen select box? I created a JSFiddle with two select boxes. The first is just to toggle the enable/disable of the chosen select.

有谁知道我如何动态启用/禁用 Bootstrap 选择框?我创建了一个带有两个选择框的 JSFiddle。第一个只是切换所选选择的启用/禁用。

$(document).on('change','#option', function(){
   // not sure what to do here
});

http://jsfiddle.net/yakitori/H38fU/3/

http://jsfiddle.net/yakitori/H38fU/3/

回答by Suthan Bala

Change your jQUery to the following

将您的 jQUEry 更改为以下内容

$(document).ready(function(){

    $(document).on('change','#option',function(){
        if($(this).val() == 1){
            // enable select box
            $("#chzn-select").attr('disabled', false).trigger("liszt:updated");
        }else{
            // disable select box
            $("#chzn-select").attr('disabled', true).trigger("liszt:updated");
        }
        $("#option").trigger("chzn:updated");
    });

});

回答by Marvil Joy

Just use $('.selectpicker').selectpicker('refresh'); after execution of your codes ... :)

只需使用 $('.selectpicker').selectpicker('refresh'); 执行您的代码后... :)