我进入新页面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">×</span><span class="sr-only">Close</span></button>
<h4 class="modal-title">Modal title</h4>
</div>
<div class="modal-body">
<p>One fine body…</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>
答案 0 :(得分:1)
你确定你也包含了jquery吗?
它需要在bootstrap.js之前出现
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
&#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">
,您现在应该会在单击按钮时弹出它。