我有一个弹出菜单,弹出菜单中有一个 iframe 代码作为文本。我有一个按钮可以启用 iframe 代码文本。然后我需要在弹出窗口关闭时禁用或显示:无 iframe 文本。因此,下次打开弹出窗口时,我必须再次单击按钮才能启用文本。我使用弹出关闭按钮制作了 display:none iframe 文本,但我无法通过单击弹出模式来完成此操作。当我将 Display:none 应用于模态类或淡入淡出类时,我什至无法启用文本。如何在弹出窗口关闭时禁用文本?
这是代码:
$(".embed-btn").on("click", function() {
$(".embed-iframe").css("display", "block");
});
$(".close").on("click", function() {
$(".embed-iframe").css("display", "none");
});
.embed-iframe{
display: none;
padding: 10px;
margin-top: 20px;
border: 1px solid #ececec;
background-color: #fafafa;
font-size: 14px;
font-weight: 400;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" crossorigin="anonymous">
<script src="https://code.jquery.com/jquery-3.2.1.slim.min.js" integrity="sha384-KJ3o2DKtIkvYIK3UENzmM7KCkRr/rE9/Qpg6aAZGJwFDMVNA/GpGFF93hXpG5KkN" crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.12.9/umd/popper.min.js" integrity="sha384-ApNbgh9B+Y1QKtv3Rn7W3mgPxhU9K/ScQsAP7hUibX39j7fakFPskvXusvfa0b4Q" crossorigin="anonymous"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/js/bootstrap.min.js" integrity="sha384-JZR6Spejh4U02d8jOt6vLEHfe/JQGiRRSQQxSfFWpi1MquVdAyjUar5+76PVCmYl" crossorigin="anonymous"></script>
<button class="btn open" data-toggle="modal" data-target="#modal1">OPEN</button>
<div class="modal fade main-div-1" id="modal1" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel" aria-hidden="true">
<div class="modal-dialog modal-div" role="document">
<div class="col-md-3 img-div">
<img src="">
</div>
<div class="col-md-9 modal-content content-div">
<div class="modal-header">
<h5 class="modal-title" id="exampleModalLabel"></h5>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
</div>
<div class="modal-body">
<button class="btn embed-btn">Enable Code</button>
<div class="embed-iframe">
<span class="embed-iframe-text">
<iframe width="" height="" src="" frameborder="" allow="accelerometer; autoplay; encrypted-media; gyroscope; picture-in-picture" allowfullscreen></iframe>
</span>
</div>
</div>
</div>
</div>
</div>
最佳答案
How I disable the text when the popup closed?
您可以使用 Bootstrap 的内置模态事件来处理这种情况。
$('#modal1').on('hide.bs.modal', function (e) {
$(".embed-iframe").css("display", "none");
})
这样,您也可以删除下面的代码行,因为 .close
按钮也会触发 hide.bs.modal
事件。
$(".close").on("click", function() {
$(".embed-iframe").css("display", "none");
});
关于javascript - 当 jQuery 关闭弹出窗口时,无法清除弹出窗口中的文本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53743799/