gpt4 book ai didi

javascript - Bootstrap 弹出窗口 : Use of callbacks in order to show/hide overlay -doesn't work

转载 作者:行者123 更新时间:2023-11-28 07:01:34 24 4
gpt4 key购买 nike

我有一个 Web 应用程序,我在其中多次使用 Bootstrap-popovers。这些弹出窗口包含 HTML,用于显示小表单等。这个想法是在显示弹出窗口时用黑色透明覆盖层“调暗”背景,以尽量减少对用户的干扰。我已经很容易地掌握了基础知识,但我真的无法按照自己的意愿使用它。

所需的功能是:每当按钮触发弹出窗口时,叠加层应显示在背景中,覆盖页面的其余部分。当弹出窗口被关闭时,无论是通过它的保存按钮,通过它的取消按钮或通过第二次点击原始触发按钮,叠加层将再次隐藏。

这是我的代码:

HTML

<html>
<head>

// loading bootstrap.css
// loading main.css
// loading jquery.min.js
// loading bootstrap.min.js
// loading main.js

</head>

<body>
<div class="fadeMe" style="display:none"></div>

// ...lots of content

<div id="newReward" class="reward-markup edit-area">
<a href="#!" id="addRewardBtn" class="btn btn-primary trigger">
ADD REWARD
</a>

<div class="head hide">
<h4>NEW REWARD</h4>
</div>
<div class="content hide">

// ...small HTML-Form which works fine

<button class="btn btn-warning pull-left" onclick="$('.popover').popover('hide');">CANCEL</button>
<button class="btn btn-warning pull-right" onclick="addReward()">SAVE</button>

</div>
</div>

</body>
</html>

主要 CSS

.fadeMe
{
opacity:0.7;
filter: alpha(opacity=20);
background-color:#000;
width:100%;
height:100%;
z-index:1;
top:0;
left:0;
position:fixed;
}

主要 JS

$(function(){

$(".trigger").on('show.bs.popover', function(){
$("div.fadeMe").show();
});
$(".trigger").on('hidden.bs.popover', function(){
$("div.fadeMe").hide();
});

});

$('.reward-markup > .trigger').popover({
html: true,
title: function () {
return $(this).parent().find('.head').html();
},
content: function () {

return $(this).parent().find('.content').html();
},
container: 'body',
placement: 'bottom'
});

虽然这不起作用。触发弹出窗口会按原样显示叠加层,但使用原始触发按钮关闭弹出层会留下叠加层而不隐藏它,此后会完全破坏弹出层功能(取消按钮功能应有)。奇怪的是,如果你用简单的警报来补充 jquery 显示/隐藏调用,那么整个事情都可以正常工作,触发按钮相应地显示警报:

$(".trigger").on('show.bs.popover', function(){
alert('The popover is about to show.');
});
$(".trigger").on('hide.bs.popover', function(){
alert('The popover is now hidden.');
});

更奇怪的是:如果你添加 both 警报和 jquery-calls 触发按钮将显示第一个警报,然后显示叠加层,但第二次点击触发按钮将不会显示第二个警报和叠加层不会隐藏:

$(".trigger").on('show.bs.popover', function(){
alert('The popover is about to show.');
$("div.fadeMe").show();
});
$(".trigger").on('hide.bs.popover', function(){
alert('The popover is now hidden.');
$("div.fadeMe").hide();
});

有人可以帮我理解这里发生了什么吗?这让我抓狂!

最佳答案

我以前遇到过这种情况......如果它对你有用,只是寻求帮助

在取消按钮中而不是 .('hide'); 弹出框 ...只需尝试再次单击原始按钮,如下所示......

<button class="btn btn-warning pull-left" onclick="$('.reward-markup > .trigger').click()">CANCEL</button>

希望对你有帮助

同时检查这个fiddle ....如果有帮助

关于javascript - Bootstrap 弹出窗口 : Use of callbacks in order to show/hide overlay -doesn't work,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33200581/

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