Jquery 引导选择isn´;t改变
我使用我的自定义选择框。内容已使用JQuery加载。如果我更改选择框,则按钮及其内容不会更新。我尝试了Jquery 引导选择isn´;t改变,jquery,html,bootstrap-select,Jquery,Html,Bootstrap Select,我使用我的自定义选择框。内容已使用JQuery加载。如果我更改选择框,则按钮及其内容不会更新。我尝试了$('select')。selectpicker() 管理此问题,但它不起作用。 你有解决办法吗 $('select#item').on("change", function () { var intID = parseInt($('select#item').val()); if (intID > 0) {
$('select')。selectpicker()代码>
管理此问题,但它不起作用。
你有解决办法吗
$('select#item').on("change", function ()
{
var intID = parseInt($('select#item').val());
if (intID > 0)
{
$.post(_this.strAjaxUrl, {
'action': 'getAction',
'intID': intID
}, function (strResponse)
{
var jsonDaten = $.parseJSON(strResponse);
if (jsonDaten.strStatus == "OK")
{
$('select#item2').html(jsonDaten.strHtml);
$('select#item2').selectpicker();
}
});
}
});
您正在将更改事件绑定到select标记。实际上,将插件应用到select标记后,select标记将被隐藏并替换为带有ul
和li
标记的“div”元素。在此之后,您的选择标记不再出现在UI上,它已隐藏。因此,您的更改事件将永远不会命中(因为您不再使用select标记)。如果您查看插件文档,您会发现有一个名为changed.bs的事件
因此,您必须实际使用插件提供的事件来触发更改事件。所以使用类似
$('select#item').on('changed.bs.select', function (e) {
// get new data to the select Tag.
});
这里比较棘手的部分是,您可以更新select标记,但是记住这个select标记是隐藏的。因此,您可能看不到UI上的更改
因此,解决方案是销毁插件。当您想用新数据更新select标记时,请使用$('select#item')。selectpicker('Destroy')代码>应用新的html。然后重新应用插件。还请记住,您必须在('changed.bs.select')上重新应用$('select#item')。函数(e){
事件绑定
让我知道这是否有帮助