You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Select2选择框无法显示求助(Bootstrap5+JQuery环境)

Select2 4.1.0rc 结合Bootstrap 5.1.3显示异常问题

我在使用Select2最新RC版本(4.1.0rc)时遇到选择框无法正常显示的问题,当前环境为Bootstrap 5.1.3、jQuery 3.6.1。

我已经尝试过切换稳定版与RC版本、使用默认主题、排查自定义主题是否存在样式覆盖,但都没能解决问题。

JavaScript代码

const locationSelect = $('#location').select2({
    ajax: {
        delay: 250,
        url: "<?= site_url('admin/select2_get_locations'); ?>",
        dataType: 'json',
        type: 'GET',
        data: function (params) {
            return {
                q: params.term
            };
        },
        processResults: function (data) {
            return {
                results: data.results
            };
        },
    },
    minimumInputLength: 3,
    escapeMarkup: function (markup) {
        return markup;
    },
});

HTML代码

<div class="col-sm-12 col-md-4 mb-4">
    <label for="location">Filtro per località</label>
    <select id="location" name="location" style="width: 100% !important">
        <option value="" selected>Seleziona</option>
    </select>
</div>

显示效果

Select2选择框显示异常

内容的提问来源于stack exchange,提问作者Developer lci-agency

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.06 21:01:05