gpt4 book ai didi

html - Bootstrap 模态元素不工作

转载 作者:太空宇宙 更新时间:2023-11-04 02:49:21 25 4
gpt4 key购买 nike

我试图在点击图片时使用模式。图像在按钮内。我已经从 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>

最佳答案

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

jQuery required

Please note that all JavaScript plugins require jQuery to be included, as shown in the starter template

另请注意,您需要在 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>

关于html - Bootstrap 模态元素不工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33293177/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com