gpt4 book ai didi

javascript - 另一个模态内的 Bootstrap 模态 - 关闭按钮问题

转载 作者:行者123 更新时间:2023-12-05 06:58:00 26 4
gpt4 key购买 nike

在我的 JSP 页面中,我有一个模态显示一个页面,该页面具有另一个模态(内部模态)。

第一个模态:

<div class="modal-dialog modal-lg"  style="background: white;  width: 90% !important">
<input type="hidden" id="report-request-data-id" value="${requestId}"/>
<div class="modal-body">
<div id="reportDataDetailsDiv"></div>
</div>
<div class="modal-footer">

<label class="btn-is float">
<spring:message code='close.label'/>
<input type="button" id="close_report_request_view" class="col-xs-3 col-lg-1 col-md-1" data-dismiss="modal" style="display: none;"/>
</label>

</div>
</div>

内部模式(加载到上面id为“reportDataDetailsDiv”的div中):

<div class="modal-dialog modal-lg" style="background: white;border-radius: 6px;">
<div class="modal-body">
<div class="modal-content">
<div class="col-centered col-lg-12 col-xs-12 ">


.....etc


<div class="modal-footer">

<label class="btn-is float">
<spring:message code='close.label'/>
<input type="button" class="cus-close-modal-btn col-xs-3 col-lg-1 col-md-1" style="display: none;"/>
</label>

</div>
</div>
</div>
</div>

当我点击内部模态中的关闭按钮时出现问题。当我这样做时,两个模态都会关闭,但我希望关闭操作对于每个模态都是独立的。我应该如何正确地做到这一点?

谢谢。

最佳答案

当您在 reportDataDetailsDiv 中加载其他模态时,您可以使用 .show() 显示它,并在 close 时显示它单击按钮,您可以删除添加到 reportDataDetailsDiv 中的整个 div

演示代码:

//suppose other modal is added like below
$(".addmodal").click(function() {
//append modal undr div
$("#reportDataDetailsDiv").html('<div class="modal-dialog modal modal-child" style="background: white;border-radius: 6px;" ><div class="modal-body"><div class="modal-content">Some message to show ....<div class="col-centered col-lg-12 col-xs-12 "><div class="modal-footer"> <label class="btn-is float"><input type="button" class="cus-close-modal-btn " value ="Close" style=""/> </label> </div></div></div></div>')
$(".modal-child").show(); //show that modal
$(this).hide();
$("#close_report_request_view").prop('disabled', true);//disable main modal button
})

//onclick of close button for modal added
$(document).on('click', '.cus-close-modal-btn', function() {
$(this).closest(".modal-child").remove(); //remove whole div
$("#close_report_request_view").prop('disabled', false);//enable main modal buton
});
<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/1.12.4/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>

<a href="#myModal" role="button" class="btn btn-primary" data-toggle="modal">Click to open modal</a>
<div class="modal-dialog modal fade modal" id="myModal" tabindex="-1" role="dialog" aria-hidden="true" style="background: white; width: 90% !important">
<input type="hidden" id="report-request-data-id" value="1" />
<div class="modal-body">
<div id="reportDataDetailsDiv"></div>
</div>
<button class="addmodal btn btn-primary">Click me to open other modal</button>
<div class="modal-footer">
<label class="btn-is float">
Close
<input type="button" id="close_report_request_view" class="col-xs-3 col-lg-1 col-md-1" data-dismiss="modal" style="display: none;"/>
</label>

</div>
</div>

关于javascript - 另一个模态内的 Bootstrap 模态 - 关闭按钮问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64742388/

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