我正在努力升级一个图片库(标准的图片库不允许我需要的一些照片的文本数量)。一切正常,但当我在按钮上运行代码以导航到上一张或下一张照片时,模式关闭,更新新照片的模式的代码运行,但该模式不会重新打开。但是,如果我在关闭该模式后插入一个警报,则一切都按预期的方式工作。
我尝试过很多事情,包括写到控制台,但这不会影响任何事情。在上面的示例中,我尝试了一个“睡眠”函数,但是它在模式关闭之前执行,因此没有产生积极的效果(除了等待模式关闭)。注释掉上面代码中的警报将运行"open_gallery_form()“中的代码,但是显示模式的代码不会触发。
function nav_button_click(event_code, ep_id) {
// close current version of modal form:
$("#imageModal").modal('hide');
// the form won't re-open without this which is frustrating ...
// tried a "sleep" routine but that fires before the form is closed (above),
// so is useless ...
// console.log("navigating"); console log doesn't do anything
alert("navigating"); // please don't change the code
// call code to refresh with new image and text, updated buttons, etc.
// and display modal
open_gallery_form(event_code, ep_id);
}
// More code here, please.<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@4.6.2/dist/css/bootstrap.min.css" integrity="sha384-xOolHFLEh07PJGoPkLv1IbcEPTNtaed2xpHsD9ESMhqIYd0nLMwNLD69Npy4HI+N" crossorigin="anonymous">
More markup here, please.
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/bootstrap@4.6.2/dist/js/bootstrap.bundle.min.js" integrity="sha384-Fy6S3B9q64WdZWQUiU+q4/2Lc9npb8tCaSX9FK7E8HnRr0Jz8D6OP9dO5Vg3Q9ct" crossorigin="anonymous"></script>
发布于 2022-10-11 19:49:41
根据伊舍伍德的评论意见如下:
setTimeout(() => { open_gallery_form(event_code, ep_id) }, "1000");工作延迟,然后调用函数,1秒的延迟似乎就足够了。我认为这件事已经完成,而且很有效。
https://stackoverflow.com/questions/74031123
复制相似问题