gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-01 01:54:02 25 4
gpt4 key购买 nike

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

这是链接

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

最佳答案

将您的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

关于javascript - onselect 从 Bootstrap 多选下拉列表中删除元素,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30683558/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com