【问题标题】:Bootstrap modal popup not showing引导模式弹出窗口未显示
【发布时间】:2013-12-18 04:59:52
【问题描述】:

我正在尝试使用 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>

当我在浏览器上运行并单击按钮时,弹出窗口仅以毫秒显示,然后再次关闭..如何防止弹出窗口像那样关闭?

【问题讨论】:

  • 看起来已经回答了,但作为旁注,您应该在结束 body 标记之前加载脚本。当他们像这样在head 中时,他们会减慢页面渲染速度。

标签: javascript jquery twitter-bootstrap modal-dialog


【解决方案1】:

试试这个

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

从你的文件中删除下面的 JS

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

DEMO

【讨论】:

  • @SridharR 我在下面添加了我的代码,但我无法让它工作,请你看看,提前谢谢你。
【解决方案2】:

试试这个...我测试了弹窗停留..

<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>

【讨论】:

  • 这非常适合我!引导程序上的示例不起作用!
【解决方案3】:

这是由于 js 冲突而发生的,因为用于运行模式的代码已经存在于 bootstrap.js 中,并且您也在使用 bootstrap-modal.js

如果您在代码中包含 bootstrap.js 以供将来参考,那么您不必包含任何额外的 js 文件来运行 bootstrap 的任何组件。 (显然除了 jQuery 文件:D)

【讨论】:

    猜你喜欢
    • 2015-02-16
    • 1970-01-01
    • 2021-08-31
    • 1970-01-01
    • 2016-04-25
    • 1970-01-01
    • 1970-01-01
    • 2020-08-01
    • 1970-01-01
    相关资源
    最近更新 更多