gpt4 book ai didi

javascript - 当我有 2 个模态时,如何在 Bootstrap 中关闭模态(弹出屏幕)

转载 作者:太空宇宙 更新时间:2023-11-04 11:30:11 29 4
gpt4 key购买 nike

         <!DOCTYPE html>
<html lang="en">
<head>
<title>Example of Bootstrap 3 Modals</title>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap- theme.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"> </script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/js/bootstrap.min.js"> </script>

<script type="text/javascript">
$(document).ready(function(){
$('.open-modal').click(function(){



$('#myModal1').modal('hide');
});


</script>

这是 CSS 部分:

     <style type="text/css">
.bs-example{
margin: 20px;
}
</style>
</head>

正文部分: 启动演示模式

          <!-- Modal HTML -->
<div id="myModal" class="modal fade">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
<h4 class="modal-title">Confirmation</h4>
</div>
<div class="modal-body">
<p>Do you want to save changes you made to document before closing?</p>
<p class="text-warning"><small>If you don't save, your changes will be lost.</small></p>

</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
<a href="#myModal1" class="btn btn-primary" data-toggle="modal">Launch Demo Modal</a>
</div>
</div>
</div>
</div>

<!-- Modal HTML -->
<div id="myModal1" class="modal fade">
<div class="modal-dialog modal-lg">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
<h4 class="modal-title">Confirmation</h4>
</div>
<div class="modal-body">
<p>Do you want to save changes you made to document before closing?</p>
<p class="text-warning"><small>If you don't save, your changes will be lost.</small></p>
<p>Do you want to save changes you made to document before closing?</p>
<p class="text-warning"><small>If you don't save, your changes will be lost.</small></p>
</div>
<div class="modal-footer">
<!--
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>-->
<a href="#myModal1" class="btn btn-default" data-dismiss="modal">close</a>
<button type="button" class="btn btn-primary">Save changes</button>
</div>
</div>
</div>
</div>
</div>
</body>
</html>

我在同一个页面中有 2 个模式。我如何在第二个模态中单击关闭按钮将关闭所有模态(弹出窗口)?你能告诉我错误的步骤吗?

最佳答案

我想这就是您要找的:

$('a[href="#myModal1"]').click(function() {
$('div[id^="myModal"]').modal('hide');
});
$('.close').click(function() {
$('div[id^="myModal"]').modal('hide');
});

jsFiddle .

希望这对您有所帮助。

关于javascript - 当我有 2 个模态时,如何在 Bootstrap 中关闭模态(弹出屏幕),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32074820/

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