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

时间:2015-06-06 13:42:46

标签: javascript jquery bootstrap-multiselect

我有两个bootstrap mutiselect下拉列表。我的要求是,如果我从第一个下拉列表中选择任何一个选项,则应从第二个下拉列表中删除所选选项。 此外,如果我取消选择它,那么它应该添加到第二个下拉列表。

这是链接

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

2 个答案:

答案 0 :(得分:0)

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

答案 1 :(得分:-1)

我不知道你想要实现多重选择。

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

JQuery Magic Suggest

有良好的文件