我已经直接从Bootstrap示例中使用了我的模态代码,并且只包括Bootstrap .js(而不是Bootstrap -modal.js)。但是,我的模态出现在灰色渐隐(背景)下面,是不可编辑的。

这是它的样子:

这是重现这个问题的一种方法。该代码的基本结构是这样的:

<body>
    <p>Lorem ipsum dolor sit amet.</p>    

    <div class="my-module">
        This container contains the modal code.
        <div class="modal fade">
            <div class="modal-dialog">
                <div class="modal-content">
                    <div class="modal-body">Modal</div>
                </div>
            </div>
        </div>
    </div>
</body>
body {
    padding-top: 50px;
}

.my-module {
    position: fixed;
    top: 0;
    left: 0;
}

你知道为什么会这样吗或者我能做些什么来弥补吗?


当前回答

我简单地设置了:

#myModal {
    z-index: 1500;
}

它工作....

对于原来的问题:

.my-module {
    z-index: 1500;
}

其他回答

我浏览了我的HTML,发现我有一个未关闭的<div>标签。关闭<div>为我解决了这个问题。 PS: <div>标签既不是模态的祖先也不是子。

角:

($('.modal-backdrop') as any).remove();

另一种方法是从bootstrap.css中的.modal- background中删除z-index。这将导致背景与身体的其他部分在同一水平线上(它仍然会褪色),你的模态在顶部。

.modal- background是这样的

.modal-backdrop {
  position: fixed;
  top: 0;
  right: 0;
  bottom: 0;
  left: 0;
  background-color: #000000;
}

在我的例子中,原因是boostrap.min.css。当我将它作为参考从HTML文件中排除后,对话框显示在模态阴影前面。

解决办法是把模态直接放在body标签下面。如果由于某些原因这是不可能的,那么只需添加一个overflow: visible属性到包含模态的标记中,或使用以下代码:

<script>
    $(document).on('show.bs.modal', '.modal', function () {
        $('.div-wrapper-for-modal').css('overflow', 'visible');
    });

    $(document).on('hide.bs.modal', '.modal', function () {
        $('.div-wrapper-for-modal').css('overflow', 'auto');
    });
</script>
<div class="div-wrapper-for-modal">
    <div class="modal hide fade">
        <div class="modal-header">
            <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
            <h3>Modal header</h3>
        </div>
        <div class="modal-body">
            <p>One fine body…</p>
        </div>
        <div class="modal-footer">
            <a href="#" class="btn">Close</a>
            <a href="#" class="btn btn-primary">Save changes</a>
        </div>
    </div>
</div>