gpt4 book ai didi

javascript - 填充选择选项不适用于 selectpicker 类

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

我有一个 Bootstrap Selectpicker 控件,我想用 Javascript 填充它,代码可以在简单的选择输入下正常工作,但是当我添加 class="selectpicker" 时,它不再工作

这是我的代码:HTML

<select id="hotspotList" class="selectpicker show-menu-arrow form-control">
</select>

Javascript

var select = document.getElementById("hotspotList");
var options = ["1", "2", "3", "4", "12"];
for(var i = 0; i < options.length; i++) {
var opt = options[i];
var el = document.createElement("option");
el.textContent = opt;
el.value = opt;
select.appendChild(el);
}

最佳答案

Use refresh(), To programmatically update a select with JavaScript, first manipulate the select, then use the refresh method to update the UI to match the new state. This is necessary when removing or adding options, or when disabling/enabling a select via JavaScript. Refer https://silviomoreto.github.io/bootstrap-select/

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

关于javascript - 填充选择选项不适用于 selectpicker 类,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33564407/

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