我制作了一个模式,可以在点击图像时弹出图像,但由于某种原因我无法使用关闭按钮。有人可以检查我的代码,看看我哪里出错了吗?或者给我一些建议......谢谢!
<div id = "myModal" class = "modal">
<div class = "modal-content">
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
<!-- Modal Content (The Image) -->
<img class="modal-content" id="mimg">
<!-- Modal Caption (Image Text) -->
<div id="caption"></div>
</div>
</div>
<img id="myImg" src="http://i0.kym-cdn.com/photos/images/newsfeed/001/023/007/f29.png" alt="Trolltunga, Norway" width="300" height="200">
答案 0 :(得分:2)
简单的例子,如果您使用bootstrap,请确保以引导方式执行。
另外,请确保参考正确。
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet" />
<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.7/js/bootstrap.min.js"></script>
#myImg {
width: 100%;
height: auto;
}
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet" />
<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.7/js/bootstrap.min.js"></script>
<button type="button" class="btn" data-toggle="modal" data-target="#myModal">Open Modal</button>
<div id="myModal" class="modal">
<div class="modal-dialog">
<div class="modal-content">
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
<!-- Modal Content (The Image) -->
<img id="myImg" src="https://pbs.twimg.com/media/BU27_rrCYAAckFP.jpg" alt="Trolltunga, Norway">
<!-- Modal Caption (Image Text) -->
<div id="caption">Modal Caption (Image Text)</div>
</div>
</div>
</div>
答案 1 :(得分:0)
您的代码未完整。尝试添加如下
<!-- Trigger the modal with a button -->
<button type="button" class="btn btn-info btn-lg" data-toggle="modal" data-target="#myModal">Open Modal</button>
<!-- Modal -->
<div id="myModal" 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">×</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>
Try it Yourself »
&#13;