Modals Bootstrap不起作用

时间:2014-12-21 15:00:18

标签: html twitter-bootstrap modal-dialog

我进入新页面live demo

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



<div class="modal fade">
  <div class="modal-dialog">
    <div class="modal-content">
      <div class="modal-header">
        <button type="button" class="close" data-dismiss="modal"><span aria-hidden="true">&times;</span><span class="sr-only">Close</span></button>
        <h4 class="modal-title">Modal title</h4>
      </div>
      <div class="modal-body">
        <p>One fine body&hellip;</p>
      </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><!-- /.modal-content -->
  </div><!-- /.modal-dialog -->
</div><!-- /.modal -->

但它不起作用。为什么呢?

在head部分中有Bootstrap CSS和Javascript:

<link href="css/bootstrap.min.css" rel="stylesheet" />
<script src="js/bootstrap.js"></script>

2 个答案:

答案 0 :(得分:1)

你确定你也包含了jquery吗?

它需要在bootstrap.js之前出现

&#13;
&#13;
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
&#13;
&#13;
&#13;

答案 1 :(得分:1)

<button type="button" class="btn btn-primary btn-lg" data-toggle="modal" data-target="#myModal">

注意data-target="#myModal"。另请注意,您的模态为<div class="modal fade">(没有ID)。

<div class="modal fade">更改为<div class="modal fade" id="myModal">,您现在应该会在单击按钮时弹出它。