简体   繁体   English

Bootstrap模式弹出窗口没有显示

[英]Bootstrap modal popup not showing

I'm trying to create a simple modal popup using Bootstrap. 我正在尝试使用Bootstrap创建一个简单的模态弹出窗口。 I got the sample from http://getbootstrap.com/javascript/#modals , my code looks like this.. 我从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>

when i run in on my browser and click the button, the popup shows only in miliseconds and then closing again..how to prevent the popup from closing like that? 当我在我的浏览器上运行并单击按钮时,弹出窗口仅在几毫秒内显示然后再次关闭..如何阻止弹出窗口关闭?

Try this 尝试这个

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

Remove below JS from your file 从您的文件中删除以下JS

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

DEMO DEMO

Try this...I tested popup stay.. 试试这个......我测试了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>

This was happening because of js conflict as the code for running modal is already present in bootstrap.js and you were also using bootstrap-modal.js 发生这种情况是因为js冲突,因为运行模式的代码已经存在于bootstrap.js中,并且您还使用了bootstrap-modal.js

For future reference if you include bootstrap.js in you code then you don't have to include any additional js file to run any components of bootstrap. 如果您在代码中包含bootstrap.js以供将来参考,那么您不必包含任何其他js文件来运行bootstrap的任何组件。 ( except of jQuery file obviously :D ) (明显除了jQuery文件:D)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM