gpt4 book ai didi

jquery - GUI 中 Bootstrap 模式完全加载后触发事件

转载 作者:行者123 更新时间:2023-12-01 03:32:32 24 4
gpt4 key购买 nike

我正在打开 Bootstrap 模式:

$('#myModal').modal({ remote: '/AccountsContact/ModalAssignCustomer?iACCO_KEY=' + iACCO_KEY });

我的问题是我需要从模态读取一些值。我想在模态完成加载并显示在 GUI 中时执行此操作。 (在模态显示之前,模态内部的GUI控件尚未生成)。

我知道这次事件:

    $(window).on('hidden.bs.modal', function() { 
$('#code').modal('hide');
alert('hidden');
});

但这里的问题是,在 GUI 上加载模态之前会触发事件 - 因此模态内的所有字段尚未生成,我无法从中读取。

有没有办法在模态完全加载到 GUI 中并且模态中的所有控件可见后触发事件?

最佳答案

请参阅下面的代码,可能会对您有所帮助。

$(document).ready(function(){
$("#myBtn").click(function(){
$("#myModal").modal("show");
});
$("#myModal").on('shown.bs.modal', function () {
alert('The modal is fully shown.');
$(this).find('p').text("This is changed text after alert");
});
});
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>



<div class="container">
<h2>Modal Events - shown.bs.modal</h2>
<!-- Trigger the modal with a button -->
<button type="button" class="btn btn-info btn-lg" id="myBtn">Open Modal</button>

<!-- Modal -->
<div class="modal fade" id="myModal" role="dialog">
<div class="modal-dialog">

<!-- Modal content-->
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal">&times;</button>
<h4 class="modal-title">Modal Header</h4>
</div>
<div class="modal-body">
<p>The <strong>shown.bs.modal</strong> event occurs when the modal is fully shown.</p>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
</div>
</div>

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

关于jquery - GUI 中 Bootstrap 模式完全加载后触发事件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48425798/

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