gpt4 book ai didi

javascript - 在外部单击时关闭弹出窗口(正文)

转载 作者:行者123 更新时间:2023-11-30 00:09:16 28 4
gpt4 key购买 nike

我有这样的弹出框:

<div class="slbb-popover popover top" role="tooltip">
<div class="arrow"></div>
<h2 class="popover-title">Speelland</h2>
<div class="popover-content">And here's some amazing content. It's very engaging. Right? </div>
<div class="text-center"><a class='btn btn-primary'>Meer informatie</a></div>
</div>

我在 JavaScript 中触发它们并给它们显示 block 。现在我想在单击外部(主体)时关闭它们,但这段代码只会执行一次:

$('body').click(function(e){
if(e.target.className == "btn-pointer")
return;

//For descendants of menu_content being clicked, remove this check if you do not want to put constraint on descendants.
if($(e.target).closest('.btn-pointer').length)
return;

console.log('check1');

//Do processing of click event here for every element except with id menu_content
if($('.popover').css('display') == 'block') {
$('.popover').css('display', 'none');
console.log('check2');
}
});

最佳答案

试试这个示例:

$(function() {

var
status = false;

$('body').click(function() {

if (!status) {

// VIEW POPUP WINDOW
status = true;
}
else {

// CLOSE POPUP WINDOW
status = false;
}

});
});

Demo (with window.open())

关于javascript - 在外部单击时关闭弹出窗口(正文),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37166056/

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