Bootstrap multiselect动态选择动态添加的字段不起作用

时间:2015-08-24 09:45:17

标签: javascript jquery twitter-bootstrap

我有我的选择:

<select id="fields_u" multiple="multiple"></select>

我动态地添加了字段:

$('#fields_u').append(fields_html);
//or
$('#example-select').append($('<option>', {
    value: 'optionValue',
    text: 'optionText'
}));

启动插件:

$('#fields_u').multiselect();

尝试选择:

$('#fields_u').multiselect('select', ['0', '1'...]);

不工作......

当DOM上的字段显示时,这对我有用。

这是一个已知问题吗?

修改<!/强> 工作,非常抱歉,愚蠢的我。我确信你将字段索引放在select而不是字段名称中。

1 个答案:

答案 0 :(得分:3)

您需要在动态附加选项后刷新多选:

$('#fields_u').multiselect('refresh');