javascript - 在 Bootstrap 模态窗口中选择在 Firefox 中不起作用

标签 javascript jquery html css twitter-bootstrap

我想制作一个模态窗口,在其中我从表单选择中选择一个选项并将其传递给进一步的功能。 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">&times;</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/

相关文章:

javascript - Facebook graph v2.0,按地理位置搜索/查询

javascript - Gulp-uglify 包装 JS

javascript - 如何制作一个4步的范围 slider ?

html - 自动播放时的 HTML5 视频缓冲量是多少

html - 使用边框的曲线

javascript - Instafeed js 在每 4 个图像周围添加包装

javascript - 如何动态调整 iframe 的大小,避免浏览器安全跨域限制?

javascript - jquery.blur() 不在 alert() 中

php - 为什么ajax在php中复制整个页面

html - 防止背景视频在移动浏览器上加载的最简单或最佳方法是什么?