簡體   English   中英

Bootstrap模式彈出窗口沒有顯示

[英]Bootstrap modal popup not showing

我正在嘗試使用Bootstrap創建一個簡單的模態彈出窗口。 我從http://getbootstrap.com/javascript/#modals獲取了示例,我的代碼看起來像這樣..

<html>
    <head>
        <script src="js/jquery.js"></script>
        <script src="js/bootstrap.js"></script>
        <script src="js/bootstrap-modal.js"></script>
        <link rel="stylesheet" href="css/bootstrap.css" />
    </head>
    <body>
        <button class="btn btn-primary btn-lg" data-toggle="modal" data-target="#myModal">
            Launch demo modal
        </button>

        <div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
          <div class="modal-dialog">
            <div class="modal-content">
              <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
                <h4 class="modal-title" id="myModalLabel">Modal title</h4>
              </div>
              <div class="modal-body">
                ...
              </div>
              <div class="modal-footer">
                <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
                <button type="button" class="btn btn-primary">Save changes</button>
              </div>
            </div>
          </div>
        </div>
    </body>
</html>

當我在我的瀏覽器上運行並單擊按鈕時,彈出窗口僅在幾毫秒內顯示然后再次關閉..如何阻止彈出窗口關閉?

嘗試這個

<script src="js/bootstrap.js"></script> // This JS have all necessary files

從您的文件中刪除以下JS

<script src="js/bootstrap-modal.js"></script>

DEMO

試試這個......我測試了popup stay ..

<html lang="en-US">
<head>
  <meta http-equiv="Content-Type" content="text/html;charset=utf-8">

  <link rel="shortcut icon" href="http://teamtreehouse.com/assets/favicon.ico">
  <link rel="icon" href="http://teamtreehouse.com/assets/favicon.ico">
  <link rel="stylesheet" type="text/css" media="all" href="css/bootstrap.min.css">
  <link rel="stylesheet" type="text/css" media="all" href="css/bootstrap-responsive.min.css">
  <link rel="stylesheet" type="text/css" media="all" href="css/global.css">
  <script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
  <script type="text/javascript" language="javascript" charset="utf-8" src="js/bootstrap.min.js"></script>
</head>

 <body>
        <button class="btn btn-primary btn-lg" data-toggle="modal" data-target="#myModal">
            Launch demo modal
        </button>

        <div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
          <div class="modal-dialog">
            <div class="modal-content">
              <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
                <h4 class="modal-title" id="myModalLabel">Modal title</h4>
              </div>
              <div class="modal-body">
                ...
              </div>
              <div class="modal-footer">
                <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
                <button type="button" class="btn btn-primary">Save changes</button>
              </div>
            </div>
          </div>
        </div>
    </body>
</html>

發生這種情況是因為js沖突,因為運行模式的代碼已經存在於bootstrap.js中,並且您還使用了bootstrap-modal.js

如果您在代碼中包含bootstrap.js以供將來參考,那么您不必包含任何其他js文件來運行bootstrap的任何組件。 (明顯除了jQuery文件:D)

暫無
暫無

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

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