从Bootstrap站点复制粘贴的模态代码不起作用

时间:2016-06-06 17:38:29

标签: javascript jquery html twitter-bootstrap

我一直在寻找一段时间,但没有找到我的问题的答案。我试图制作一个模态,但它没有显示出来。我的模态代码和触发模态的按钮只是从官方引导程序站点复制粘贴。我不知道出了什么问题,但如果你想知道我的进口产品,我已经进口了以下产品(按顺序):

  1. <link rel="stylesheet" type="text/css" href="css/bootstrap.min.css">
  2. <script type="text/javascript" href="js/jquery-2.2.4.js"></script>
  3. <script type="text/javascript" href="js/bootstrap.min.js"></script>
  4. <link rel="stylesheet" type="text/css" href="css/style.css">
  5. 请帮帮我。

      

    修改

    这是我复制和粘贴的模态代码

    &#13;
    &#13;
    <!-- Button trigger modal -->
    <button type="button" class="btn btn-primary btn-lg" data-toggle="modal" data-target="#myModal">
      Launch demo modal
    </button>
    
    <!-- Modal -->
    <div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
      <div class="modal-dialog" role="document">
        <div class="modal-content">
          <div class="modal-header">
            <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></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>
    &#13;
    &#13;
    &#13;

2 个答案:

答案 0 :(得分:0)

正确添加jQueryBootstrap个链接。使用CDN提供的上述最新版本,您的示例工作正常。

&#13;
&#13;
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js"></script>
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" rel="stylesheet"/>
<!-- Button trigger modal -->
<button type="button" class="btn btn-primary btn-lg" data-toggle="modal" data-target="#myModal">
  Launch demo modal
</button>

<!-- Modal -->
<div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
  <div class="modal-dialog" role="document">
    <div class="modal-content">
      <div class="modal-header">
        <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></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>
&#13;
&#13;
&#13;

修改

通过设置style.css

,检查display:none;中是否覆盖任何基本的Bootstrap模态类

答案 1 :(得分:0)

在基本的html和css上执行Udacity教程时,从示例中添加模态时遇到了同样的问题。我添加了这些代码行,它起作用了:

<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js"></script>
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" rel="stylesheet"/>

我确信我已经将模态包含在我自定义下载的bootstrap版本中,所以我认为它们没有帮助,但是只要我在标题中添加这些行,它就像我预期的那样工作。有关如何将其添加到标题的更精确示例:

<head>
    <!--these 3 added imports made the modal work-->
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
    <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js"></script>
    <link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" rel="stylesheet"/>
    <title>MyAwesomeWebpage</title>
</head>

PS别忘了你的其他样式表和javascript文档。