动态将表单元素添加到Bootstrap多重选择库 [英] Adding form elements dynamically to Bootstrap multiselect library

查看:262
本文介绍了动态将表单元素添加到Bootstrap多重选择库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用Bootstrap多选库( http://davidstutz.github .io/bootstrap-multiselect/#getting-started )以使用表单控件,即Bootstrap下拉菜单中的复选框.我正在尝试动态填充选项,而不是示例.但是,动态添加元素会导致下拉列表在选择表单元素后立即关闭(可能与事件传播有关),并且不允许我处理其他复选框.我该如何解决这个问题?

I am trying to use the Bootstrap multiselect library (http://davidstutz.github.io/bootstrap-multiselect/#getting-started ) to use form controls, namely checkboxes in a Bootstrap dropdown. I am trying to populate options dynamically as opposed to the example. However, adding elements dynamically causes the dropdown to close immediately after selecting a form element (perhaps this has to do with event propagation) and does not allow me to manipulate other checkboxes. How do I resolve this issue ?

具体来说,我该如何动态地将元素填充到 select 标记中?示例:

Specifically how do I populate elements dynamically into the select tag ? The example:

 <select id="example-getting-started" multiple="multiple">
    <option value="cheese">Cheese</option>
    <option value="tomatoes">Tomatoes</option>
    <option value="mozarella">Mozzarella</option>
    <option value="mushrooms">Mushrooms</option>
    <option value="pepperoni">Pepperoni</option>
    <option value="onions">Onions</option>
</select>

任何对此的帮助将不胜感激!

Any help with this would be greatly appreciated !

推荐答案

$('#example-getting-started').append($('<option>', {
      value: 'optionValue',
      text : 'optionText'
    }));

然后:

$('#example-getting-started').multiselect('rebuild');

这篇关于动态将表单元素添加到Bootstrap多重选择库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆