【发布时间】:2026-01-10 12:05:02
【问题描述】:
我正在创建一个非常简单但稍加调整的模式来显示 iFrame。我通过一个javascript函数和bootstrap提供的模态调用函数打开模型。在我的模式中,我放置了一个用于关闭模式的图标。如果我单击此关闭图标,模式将不会隐藏。我使用带有引导程序提供的.modal('show') 和.modal('hide') 函数的javascript onclick。模态不会隐藏,但我的控制台日志被触发。
我知道有很多类似问题的问题,但这些问题不包含我正在寻找的答案。我知道 html 中的 css 是不正确的,但我正在做一些快速原型设计,所以请原谅我。
代码
打开模态链接
<a href="#" onClick="openFeedback('getBootstrap')">Klik hier om de website te bekijken</a>
模态html
<!-- Modal -->
<div class="modal fade" id="iframe_feedback" style="padding-top: 20px;">
<i class="ion-close-round close-modal" style="position: fixed; right: 40px; font-size: 32px; color: white; top: 40px; cursor: pointer;" onClick="closeModal()"></i>
<div class="body-modal" style="max-width: 90%; margin: 0 auto; overflow: scroll;">
<div id="clip" style="overflow:scroll;">
<iframe src="/dashboard" style=" width:2600px; height: 1600px;"></iframe>
</div>
</div>
</div>
JS
function openFeedback(link) {
$('#iframe_feedback').modal('show');
console.log(link);
};
function closeModal() {
$("#iframe_feedback").modal('hide');
console.log('Close fired');
};
我的主要问题是我的模态正在显示,同时为显示和隐藏触发console.log,但是在单击关闭按钮后,模态不会隐藏。
【问题讨论】:
-
您在控制台中看到了什么吗?也许您遇到了错误。
-
@FedericoNavarrete 就像我说的,我的 console.log 两次都被触发了,所以我会注意到是否有错误。看不到任何问题或错误。
-
您是否尝试过在 jquery 中使用匿名函数而不是使用点击事件?
$('.close-modal').on('click'....也是如此。
标签: javascript jquery twitter-bootstrap bootstrap-4