Bootstrap模态重叠

时间:2016-05-03 18:31:28

标签: html twitter-bootstrap

我有一个简化的页面,如下所示:

<html>
<form>
//form contents here
//modal 1 here
<div class="modal fade" id="addTime" tabindex="-1" role="dialog" aria-labelledby="addTimeLabel">
<div class="modal-content">
<div class="modal-header">
<div class="modal-body">
<div class="modal-footer">
</div></div></div>
</form>
// insert duplicate modals here (2 of them)
</html>

表单中的模态运作完美,但是当我点击按钮调出模态2和3时,它们会出现在第一个模态窗口中?我该如何解决这个问题?

编辑:如果我完全删除第一个模态,2和3工作完美....但我也需要第一个模态!

1 个答案:

答案 0 :(得分:0)

&#13;
&#13;
$(document).ready(function () {

    $('#openBtn').click(function () {
        $('#myModal').modal({
            show: true
        })
    });

        $(document).on('show.bs.modal', '.modal', function (event) {
            var zIndex = 1040 + (10 * $('.modal:visible').length);
            $(this).css('z-index', zIndex);
            setTimeout(function() {
                $('.modal-backdrop').not('.modal-stack').css('z-index', zIndex - 1).addClass('modal-stack');
            }, 0);
        });


});
&#13;
/* crazy batman newspaper spinny thing */
 .rotate {
    transform:rotate(180deg);
    transition:all 0.5s;
}
.rotate.in {
    transform:rotate(1800deg);
    transition:all 1.5s;
}
&#13;
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.2.3/jquery.min.js"></script>
  <link rel="stylesheet" href="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css">
  <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.0/jquery.min.js"></script>
  <script src="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js"></script>

<h2>Stacked Bootstrap Modal Example.</h2>
 <a data-toggle="modal" href="#myModal" class="btn btn-primary">Launch modal</a>

<div class="modal fade" id="myModal">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
                	<h4 class="modal-title">Modal 1</h4>

            </div>
            <div class="container"></div>
            <div class="modal-body">Content for the dialog / modal goes here.
                <br>
                <br>
                <br>
                <p>more content</p>
                <br>
                <br>
                <br>	<a data-toggle="modal" href="#myModal2" class="btn btn-primary">Launch modal</a>

            </div>
            <div class="modal-footer">	<a href="#" data-dismiss="modal" class="btn">Close</a>
	<a href="#" class="btn btn-primary">Save changes</a>

            </div>
        </div>
    </div>
</div>
<div class="modal fade rotate" id="myModal2">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
                	<h4 class="modal-title">Modal 2</h4>

            </div>
            <div class="container"></div>
            <div class="modal-body">Content for the dialog / modal goes here.
                <br>
                <br>
                <p>come content</p>
                <br>
                <br>
                <br>	<a data-toggle="modal" href="#myModal3" class="btn btn-primary">Launch modal</a>

            </div>
            <div class="modal-footer">	<a href="#" data-dismiss="modal" class="btn">Close</a>
	<a href="#" class="btn btn-primary">Save changes</a>

            </div>
        </div>
    </div>
</div>
<div class="modal fade" id="myModal3">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
                	<h4 class="modal-title">Modal 3</h4>

            </div>
            <div class="container"></div>
            <div class="modal-body">Content for the dialog / modal goes here.
                <br>
                <br>
                <br>
                <br>
                <br>	<a data-toggle="modal" href="#myModal4" class="btn btn-primary">Launch modal</a>

            </div>
            <div class="modal-footer">	<a href="#" data-dismiss="modal" class="btn">Close</a>
	<a href="#" class="btn btn-primary">Save changes</a>

            </div>
        </div>
    </div>
</div>
<div class="modal fade" id="myModal4">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
                	<h4 class="modal-title">Modal 4</h4>

            </div>
            <div class="container"></div>
            <div class="modal-body">Content for the dialog / modal goes here.</div>
            <div class="modal-footer">	<a href="#" data-dismiss="modal" class="btn">Close</a>
	<a href="#" class="btn btn-primary">Save changes</a>

            </div>
        </div>
    </div>
</div>
&#13;
&#13;
&#13;

检查此jsfiddle:http://jsfiddle.net/CxdUQ/