javascript - Bootstrap/JQuery : Cannot get modal to show

标签 javascript jquery twitter-bootstrap bootstrap-modal

好吧,所以我讨厌成为那个发布作业问题的人,但我已经到了极限。

每当我单击按钮时,我都需要一个模式来上诉。

我已经尝试过:

  • 显示模式的 data-* 方式(如下面的代码所示)
  • 使用 $(#mainModal).modal('show') 通过 JS 函数显示模态框
  • 注释掉 jQuery 版本,以免与 Bootstrap 的 jQuery 冲突。

互联网上似乎没有任何东西可以工作。有人介意告诉我如何显示模式吗?

非常感谢!

<!DOCTYPE html>
<html lang="en">

   <head>
        <meta charset="UTF-8">
        <title>Chatty</title>

        <!-- Styles -->
        <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.0.0/jquery.min.js"></script>
        <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.2.0/css/bootstrap.min.css">

        <style>

        body { 
            background-color: #333333;
            padding-top:50px;
        }

        h1 {
            color: white;
        }

        body, h1 {
            padding-bottom: 50px;
        }

        .button-spacing {
            margin-bottom: 50px;
        }

        </style>


        <script>

        </script>

   </head>

   <body class="container">

        <h1 class="text-center">Chatty App</h1>

        <button type="button" class="btn btn-success btn-lg button-spacing col-lg-6 col-lg-offset-3 col-md-8 col-md-offset-2 col-sm-8 col-sm-offset-2" data-toggle="modal" data-target="#mainModal">Post New Tweet</button>

        <!-- Modal -->
        <div id="mainModal" class="modal fade" role="dialog">
          <div class="modal-dialog">

            <!-- Modal content-->
            <div class="modal-content">
              <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal">&times;</button>
                <h4 class="modal-title">Modal Header</h4>
              </div>
              <div class="modal-body">
                <p>Some text in the modal.</p>
              </div>
              <div class="modal-footer">
                <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
              </div>
            </div>

          </div>
        </div>
        </div>

   </body>

</html>

最佳答案

您没有加载 Javascript 文件。

<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.0.0/jquery.min.js"></script
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.2.0/css/bootstrap.min.css">
<!-- missing this line -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.2.0/js/bootstrap.min.js">

关于javascript - Bootstrap/JQuery : Cannot get modal to show,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40162261/

相关文章:

javascript - 基于字段值的 Angular 过滤

javascript - 仅当数据可用时,才在 vuejs 中条件渲染另一个元素或父元素

Javascript:从外部设置函数中删除绑定(bind)的事件处理程序

javascript - 限制 On Bootstrap 切换开关的总数

javascript - javascript跨浏览器二进制数据处理

php - 跨域Ajax数据

jquery - Rails session 正在重置

javascript - 除非文本框有文本,否则如何限制按钮

css - 无法连接 Bootstrap 样式表

jquery - Bootstrap 切换复选框不适用于 Angular 2 组件