我想制作一个模态窗口,在其中我从表单选择中选择一个选项并将其传递给进一步的功能。 The problem is, that when the select list drops down, i can't change the selected option.此问题仅在 Firefox 中出现。在 Chrome 中它似乎运行良好。
下面是我在我的应用程序中使用的代码。除了 Bootstrap 之外,我没有任何其他样式或脚本。
<button type="button" class="btn btn-primary btn-lg" data-toggle="modal" data-target="#myModal">
Launch
</button>
<div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" data-backdrop="static">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">×</span></button>
<h4 class="modal-title" id="myModalLabel">Modal title</h4>
</div>
<div class="modal-body">
<div>
<select class="form-control" >
<option selected>1</option>
<option>2</option>
<option>3</option>
<option>4</option>
<option>5</option>
</select>
</div>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
<button type="button" class="btn btn-primary" id='generate'>Generate</button>
</div>
</div>
</div>
</div>
最佳答案
我删除了模态的属性 tabindex="-1"
(或设置为 0),并添加了 javascript:
$.fn.modal.Constructor.prototype.enforceFocus = $.noop;
https://github.com/select2/select2/issues/4091#issuecomment-172633858 ->
解决方案:https://github.com/select2/select2/issues/600#issuecomment-102857595
关于javascript - 在 Bootstrap 模态窗口中选择在 Firefox 中不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35138690/