【问题标题】:How to remove "disable" attribute for class "selectpicker" using jQuery如何使用 jQuery 删除类“selectpicker”的“禁用”属性
【发布时间】:2019-07-24 08:43:00
【问题描述】:

在选择第1个下拉列表时,在第二个下拉列表中删除select“已禁用”属性。

我尝试了一些解决方案,但没有解决我的问题。我尝试过的解决方案如下:

1)$('#xyz').prop("disabled", false);

2)$("#xyz").attr('disabled', true).trigger("liszt:updated");

分享我的代码如下:

HTML

//This is 2nd Dropdown    
<select id="xyz" class="selectpicker form-control" multiple title="-- Select --" disabled>
       <option value="" disabled>-- Select --</option>
       <option value="A">A</option>                                     
       <option value="B">B</option>                                     
    </select>

JS

$("#1stdropdown").change(function() {       //This is 1st Dropdown      
    if ($("#1stdropdown").val() == "") {
        $("#btnSubmit").attr('disabled', true);
        $("#xyz").append($("<option>",{value: "",text: "-- Select --"}));
    }
    else {
        $("#btnSubmit").attr('disabled', false); 
        $("#xyz").removeAttr("disabled").prop("disabled", false);  // I am stuck here
    }
});

【问题讨论】:

    标签: jquery bootstrap-selectpicker


    【解决方案1】:

    试试这个:

    $("#xyz").attr('disabled',true);
    
    $('#xyz').selectpicker('refresh');
    

    您应该在更新后刷新选择器。

    【讨论】:

    • 我已经尝试过这段代码,现在下拉菜单可以选择但没有出现值,在我上面的例子中,没有出现 A & B 值。
    • $("#xyz").attr('disabled',false); //修复你的
    • @mastersuse 如果有帮助,您可以接受答案。 :)
    猜你喜欢
    • 2012-11-17
    • 2011-11-30
    • 2016-08-11
    • 2019-01-02
    • 2012-01-08
    • 1970-01-01
    • 1970-01-01
    • 2017-08-10
    • 1970-01-01
    相关资源
    最近更新 更多