我试过多种组合,就是无法清除这个控件。 我使用的是 jquery 3.2.1,控件是 Bootstrap-select v1.13.1 这里是链接 https://developer.snapappointments.com/bootstrap-select/ .
我想清除 teamPositionFilter 选项,只要 groupFilter 在它改变之前。现在它在每次更改后附加值。我可以单步执行 javascript 代码,但它不会更改列表。
@Html.DropDownList("groupFilter", (SelectList)(@ViewBag.GroupList), new { @class = "singleselectpicker col-md-3", title = "Group:", data_header = "Select Group:" })
@Html.DropDownList("teamPositionFilter", (MultiSelectList)(@ViewBag.TeamPositionList), new { @class = "multiselectpicker col-md-3", multiple = "multiple", title = "Team Position:", data_header = "Select one or more Team Positions:" })
$(function() {
$('#groupFilter').change(function () {
var #teamPositionFilter = $('#teamPositionFilter');
#teamPositionFilter.find('option').remove();
#teamPositionFilter.selectpicker('refresh');
});
$('.singleselectpicker').selectpicker({
showTick: true,
tickIcon: 'glyphicon-pushpin',
liveSearch: true,
liveSearchStyle: 'contains',
selectOnTab: true,
showContent: true,
size: 10,
width: 'false'
});
$('.multiselectpicker').selectpicker({
actionsBox: true,
selectAllText: 'Select All',
deselectAllText: 'Deselect All',
selectedTextFormat: 'count',
showTick: true,
tickIcon: 'glyphicon-pushpin',
liveSearch: true,
liveSearchStyle: 'contains',
selectOnTab: true,
showContent: true,
size: 10,
width: 'false',
multipleSeparator: ', '
});
});
最佳答案
列出了一个旧问题 here
要删除所选项目:
var itemSelectorOption = $('#select-id option:selected');
itemSelectorOption.remove();
$('#select-id').selectpicker('refresh');
关于jquery - 在进行选择更改时从 Bootstrap-Select 中删除选项,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50887686/