gpt4 book ai didi

javascript - 每次点击后的确认模式。第一次有效,然后失败。 (模态上的模态)

转载 作者:行者123 更新时间:2023-11-28 04:47:41 26 4
gpt4 key购买 nike

我正在使用 Bootstrap 启动选择模式,然后启动表单模式,最后在用户单击发送后启动确认模式。

这第一次工作正常,但是之后,确认模式不会弹出,它只是简单地退出。

这是我的代码:

HTML:

<button type="button" class="btn" data-toggle="modal" data-target="#chooseModal">Open</button>

<!-- Select One Modal -->
<div class="modal fade" id="chooseModal" 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>
<h2 class="modal-title" id="myModalLabel">Select An Option</h2>
</div>
<div class="modal-body">
<button type="button" class="btn" data-toggle="modal" data-target="#myForm">Click to Email</button>
<button type="button" class="btn" data-toggle="modal" data-target="#chooseModal">Click to Do Something Else</button>
</div>
</div>
</div>
</div>

<!-- Email Form Modal-->
<div class="modal fade" id="myForm" 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">Email</h4>
</div>
<div class="modal-body">

<div class="row">
<div class="col-xs-12" id="emailInput">
<h4>To:</h4>
<input type="text" name="email" id="email">
</div>
<div class="col-xs-12">
<h4>Subject:</h4>
<input type="text" value="subject" name="emailSubject" id="emailSubject">
</div>
<div class="col-xs-12">
<h4>Body:</h4>
<textarea rows="4" id="emailBody"></textarea>
</div>
<div class="col-xs-1">
<button onclick="confirmAlert()" type="button" class="btn" data-toggle="modal" data-target="#myForm">Send</button>
</div>
</div>

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


<!-- Confirmation Modal -->
<div class="modal fade" id="PDFconfirmation" 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>
<h2 class="modal-title" id="myModalLabel">Thank You!</h2>
</div>
<div class="modal-body">
<h2>Your message has been sent.</h2>
</div>
</div>
</div>
</div>

Javascript:

function confirmAlert(){ 

$(".modal, .modal-backdrop").hide();

$('#PDFconfirmation').modal('show');

setTimeout(function(){
$("#PDFconfirmation, .modal, .modal-backdrop").hide();
}, 2000);

}

最佳答案

您应该将 JS 代码更改为:

function confirmAlert(){ 

$("#chooseModal").modal('hide');

$('#PDFconfirmation').modal('show');

setTimeout(function(){
$("#PDFconfirmation").modal('hide');
}, 2000);

}

但是,您可以改进此代码,但现在您可以更好地了解应该如何切换(显示/隐藏)模态以防止此类错误。

关于javascript - 每次点击后的确认模式。第一次有效,然后失败。 (模态上的模态),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43213183/

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