我使用 Bootstrap 按钮下拉菜单来显示表单。我已经通过调用禁用下拉菜单消失 onclick(当用户操作表单时)stopPropagation。表单的元素之一是下拉列表。如果我使用本机 html 选择元素,一切都很好(除了看起来很丑)。如果我用 bootstrap-select 替换它(它模仿 div 的选择),我无法选择一个值(因为按钮下拉列表中没有足够的位置)。我尝试应用一种解决方法来指定container: 'body'引导选择。它有助于查看下拉列表值,但是当我选择元素时按钮下拉列表关闭(我猜它发生在 boostrap-select 属于主体,它高于应用点击传播的按钮下拉列表)。
<div class="btn-group">
<button type="button" class="btn btn-primary btn-lg dropdown-toggle" data-toggle="dropdown">
Take <span class="caret"></span>
</button>
<ul class="dropdown-menu" role="menu">
<li>
<form>
<select id="mySelect" class="selectPicker">
<option>1</option>
</select>
</form>
</li>
</ul>
</div>
<script type="text/javascript">
$('.dropdown-menu').click(function(e) {
e.stopPropagation(); //This will prevent the event from bubbling up and close the dropdown when you type/click on text boxes.
});
$('.selectpicker').selectpicker({container: 'body'});
</script>