Bootstrap模态元素不起作用

时间:2015-10-23 00:51:57

标签: html css twitter-bootstrap

我在点击图片时试图使用模态。图像在按钮内。 我已经从Bootstrap网站复制了代码,但没有任何工作。我在html文档的开头链接了bootstrap.css和bootstrap.min.js。 请帮忙!

<div class="col-xs-6 col-md-4">
      <button type="button" data-toggle="modal" data-target="#myModal"> 
        <h4>SHORT SLEEVED SHIRT<br><br>$20</h4>
        <img src="images/femaleshortsleeved.jpg">
      </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>
</div>

1 个答案:

答案 0 :(得分:2)

Bootstrap documentation中所述,您需要包含jQuery。

  

需要jQuery

     

请注意,所有JavaScript插件都需要包含jQuery,如启动模板

中所示

另请注意,您需要在 Bootstrap Javascript文件之前包含它

以下是您的代码工作示例:

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

<div class="col-xs-6 col-md-4">
  <button type="button" data-toggle="modal" data-target="#myModal">
    <h4>SHORT SLEEVED SHIRT<br><br>$20</h4>
    <img src="images/femaleshortsleeved.jpg">
  </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>
</div>