【问题标题】:Bootstrap select doesn't update selected options properly引导选择无法正确更新选定的选项
【发布时间】:2019-01-06 08:46:46
【问题描述】:

I am using bootstrap select plugin, When the options at bottom of the select is selected the bootstrap select does not refresh the select properly(the previously selected options remains as selected as the boostrap select does not remove the selected class properly), 我是否必须在引导选择上监听更改事件并刷新选项,这在选项较少时不会发生,这可能是什么解决方案

  $('.selectpicker').selectpicker({
  });

Js 小提琴:

https://jsfiddle.net/aarthi_101/79rz3j1w/18/,

我在 github 上发布了一个问题, https://github.com/snapappointments/bootstrap-select/issues/85

【问题讨论】:

  • 您的 jsfiddle 工作正常,之前选择的选项不会保持选中状态。你还有这个问题吗?
  • 是的,还是有这个问题,您可以尝试选择选项列表底部的选项
  • 我已经编辑了我的问题并添加了一个截图。请看一下

标签: jquery twitter-bootstrap bootstrap-4 bootstrap-select


【解决方案1】:

更改选择时只需刷新即可。 代码:

$('select').on('change',function(){

   $(this).selectpicker('refresh');
});

【讨论】:

  • 我的情况是,如果在页面加载完成时引导选择不在活动引导选项卡中(我的页面有 3 个选项卡),则更改事件后选择不会刷新。这个答案对我很有帮助,谢谢:)
  • @ChiaChi 很高兴我的回答对你有所帮助:)
【解决方案2】:

试试这个小提琴:https://jsfiddle.net/h6dkgL35/

我添加了一个脚本以从先前选择的选项中删除“活动”类。

  $('.dropdown-item').on('click', function() {
  $('.dropdown-item').removeClass('active');
  $(this).addClass('active');
  });

我还添加了一种样式,因为新选择的选项具有蓝色背景而不是紫色。

【讨论】:

  • 我无法得到你在小提琴中所说的结果。该问题仍然存在
猜你喜欢
  • 1970-01-01
  • 2013-05-29
  • 1970-01-01
  • 2019-05-07
  • 1970-01-01
  • 2015-09-01
  • 2015-02-07
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多