截止2026-01-09号,bootstrap-select 官方并没有完全支持 bootstrap5。
github:
https://github.com/snapappointments/bootstrap-select
documentation
https://developer.snapappointments.com/bootstrap-select/
以下方法可以在 bootstrap5 中使用,但有个error,完全不影响正常使用。
还有个选择,使用完全支持bootstrap5的下拉多选插件,tom-select,请依具体情况而定。
1, 下载 bootstrap-select 具体版本
https://github.com/snapappointments/bootstrap-select/releases
下载完后,要引入项目,必要文件为,注意顺序:
bootstrap.css
bootstrap-select.css
注意这里:bootstrap.bundle.min.js (bundle已含有popper.js,否则bootstrap.js + popper.js)
bootstrap-select.js
2,添加js初始代码
在你使用bootstrap-select前,必须指定版本,js代码为
$.fn.selectpicker.Constructor.BootstrapVersion = '5';
3,如何获取已选择的多个值
$('#yourSelectId').val()即可,返回的是一个字符串数组,[] 或 ['aa','bb']
4,如何初始化值
$('#yourSelectId').val(类型为js数组)
13万+

被折叠的 条评论
为什么被折叠?



