【问题标题】:How to enable/disable BsMultiSelect如何启用/禁用 BsMultiSelect
【发布时间】:2021-10-01 15:31:16
【问题描述】:

我正在尝试使用BsMultiSelect

如何手动启用/禁用选择菜单?

我能够像这样成功禁用菜单

// remove all options
removeOptions(select); 

// disable the select element
select.setAttribute('disabled', true); 

// update the data since all options were removed
select.updateData();

// update the appearance of the menu since it is now disabled
select.updateAppearance();

然后我尝试像这样启用它,但没有成功

// add new options to the select element
addOptions(select);

// enable the select element
select.removeAttribute('disabled');


// update the data since new options were added
select.updateData();

// update the appearance of the menu since it is now enabled
select.updateAppearance();

【问题讨论】:

    标签: javascript bsmultiselect


    【解决方案1】:

    有点晚了,但我遇到了同样的问题,并通过 bsMultiSelect 的内置选项 getDisabled 解决了它,它需要 true 或 false。

    然后我使用$('#yourMultiSelectOption').attr('custom-data-attr', false/true).bsMultiSelect("UpdateDisabled")首先将属性更改为所需的选项,然后手动触发bsMultiSelect的更新。

    $(#yourMultiSelectOption).bsMultiSelect({
        getDisabled: function () {
                         return $("#yourMultiSelectOption").attr('custom-data-attr') === 'true';
                     },
        [other options...]
    })

    【讨论】:

      猜你喜欢
      • 2012-11-05
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-04-08
      • 2014-04-27
      • 2012-12-18
      • 1970-01-01
      相关资源
      最近更新 更多