onselect 从 Bootstrap 多选下拉列表中删除元素

onselect remove element from Bootstrap Multiselect dropdown

我有两个 bootstrap mutiselect 下拉菜单。我的要求是,如果我 select 第一个下拉列表中的任何一个选项,那么 selected 选项应该从第二个下拉列表中删除。 另外,如果我 deselect 它那么它应该被添加到第二个下拉列表中。

这里是link

https://jsfiddle.net/cpxavier/6escna8k

不知道你要实现多选什么

但是这个jQuery库非常适合多选,易于操作,更灵活。

JQuery Magic Suggest

有良好的文档

把你的document.ready改成这个

$(document).ready(function() {
    $('.multi2').multiselect({ // this is the second multiselect
        includeSelectAllOption: false,
        nonSelectedText: 'Select Teams',
    });
    $('.multi1').multiselect({ // this is the first multiselect
        includeSelectAllOption: false,
        nonSelectedText: 'Select Teams',
        onChange: function(option, checked, select) { // implement onChange listener
        // clear all selection of the second dropdown - This will be called whenever there's a change in the first multiselect
        // You can think of puting in some additional conditions here.
            $('.multi2').multiselect('clearSelection', false);
        }
    });
});

您还需要将 html 更新为 -

<select id="team0" name="team0[]" class="multi1" multiple="multiple"><!-- first dropdown-->

<select id="team1" name="team0[]" class="multi2" multiple="multiple"><!-- second dropdown-->

<iframe width="100%" height="300" src="//jsfiddle.net/yellen/fw32gwd2/embedded/" allowfullscreen="allowfullscreen" frameborder="0"></iframe>

更多参考:http://davidstutz.github.io/bootstrap-multiselect/#methods