簡體   English   中英

引導模式對話框未顯示(黑色背景顯示)

[英]bootstrap modal dialog not showing (black background showing)

我在 html 文件中有兩個模式對話框(導致問題)。

哪個模態對話框首先放置在 html 文件的序列中,在按鈕單擊時正確顯示(反之亦然)。

兩個模態對話框都有唯一的 id 並且被適當地調用,但是一個模態對話框沒有顯示(如果稍后單獨調用)。

     <!-- Modal dialog xyz is the first in the sequence of html code -->
     <div class="modal fade" id="xyzModal" tabindex="-1" role="dialog" aria-labelledby="xyzModalTitle" aria-hidden="true">
        <div class="modal-dialog modal-dialog-centered" role="document">
          .....
        </div>
     </div>

     <!-- Modal dialog abc is the second M.D in the sequence of html code -->
     <div class="modal fade" id="abcModal" tabindex="-1" role="dialog" aria-labelledby="abcModalTitle" aria-hidden="true">
        <div class="modal-dialog modal-dialog-centered" role="document">
          .....
        </div>
     </div>

我在調用模態對話框時到底哪里出錯了。

對於相應的按鈕點擊,我也在使用隱藏/顯示功能,但不起作用。

     $("#xyzModal").modal('hide');
     $("#abcModal").modal('show');

如果您需要在打開新模式之前隱藏所有模式,那么最好的做法是:

$(".modal").modal('hide');
$("#abcModal").modal('show');

這可確保在您打開新模式之前隱藏所有模式。

試試下面的代碼。 它正在工作。 使用下面的 CDN 和腳本。

<!DOCTYPE html>
<html>
<head>
    <title>Test Modal</title>
    <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css" integrity="sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T" crossorigin="anonymous">
</head>
<body>

    <!-- Button trigger modal -->
    <button type="button" class="btn btn-primary" data-toggle="modal" data-target="#xyzModal">
        Launch xyzModal modal
    </button>

    <!-- Button trigger modal -->
    <button type="button" class="btn btn-primary" data-toggle="modal" data-target="#abcModal">
        Launch abcModal modal
    </button>

    <!-- Modal dialog xyz is the first in the sequence of html code -->
    <div class="modal fade" id="xyzModal" tabindex="-1" role="dialog" aria-labelledby="xyzModalTitle" aria-hidden="true">
        <div class="modal-dialog modal-dialog-centered" role="document">
            .....
        </div>
    </div>

    <!-- Modal dialog abc is the second M.D in the sequence of html code -->
    <div class="modal fade" id="abcModal" tabindex="-1" role="dialog" aria-labelledby="abcModalTitle" aria-hidden="true">
        <div class="modal-dialog modal-dialog-centered" role="document">
            .....
        </div>
    </div>

    <script src="https://code.jquery.com/jquery-3.3.1.slim.min.js" integrity="sha384-q8i/X+965DzO0rT7abK41JStQIAqVgRVzpbzo5smXKp4YfRvH+8abtTE1Pi6jizo" crossorigin="anonymous"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.7/umd/popper.min.js" integrity="sha384-UO2eT0CpHqdSJQ6hJty5KVphtPhzWj9WO1clHTMGa3JDZwrnQq4sF86dIHNDz0W1" crossorigin="anonymous"></script>
    <script src="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/js/bootstrap.min.js" integrity="sha384-JjSmVgyd0p3pXB1rRibZUAYoIIy6OrQ6VrjIEaFf/nJGzIxFDsf4x0xIM+B07jRM" crossorigin="anonymous"></script>

    <script type="text/javascript">
        $('#xyzModal').on('shown.bs.modal', function () {
            //
        })

        $('#abcModal').on('shown.bs.modal', function () {
            //
        })

    </script>
</body>
</html>

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM