【问题标题】:Twitter-bootstrap popover does not allow content below to functionTwitter-bootstrap popover 不允许下面的内容起作用
【发布时间】:2014-01-18 06:45:03
【问题描述】:

我有一个带有 3 个 Twitter 引导弹出按钮的页面,单击这些按钮会显示一个带有 HTML 内容的隐藏 div。我在右上角添加了一个 X 来关闭弹出框。

我的问题发生在弹出窗口打开并覆盖其下方的内容然后关闭时,它下方的内容即链接到另一个页面的按钮不再可访问并且您无法再单击它。

在检查器中,我可以看到隐藏的弹出框,即带有内容的 div,位于我要单击的按钮的顶部,因此我无法访问它。

奇怪的是,当我点击实际的弹出框按钮关闭弹出框时,它完全消失了,我可以点击下面的按钮,但是当我点击关闭 X 时,我不能。

我该如何解决这个问题?

页面链接:(http://bit.ly/1j1AW4i)

按钮代码:

<button id="popoverBtn1" class="popoverThis btn btn-default" data-placement='bottom'>
    Learn More <span class="glyphicon glyphicon-circle-arrow-right"></span>
</button>
<div id="popoverContent1" class="hide">
    <strong>Ideal for:</strong> Qualified clients who want to continue having the convenient access to funds that a home equity line of credit provides.
    <br /><br />
    <strong>What:</strong> Apply for a new Access 3<sup>&reg;</sup> Equity Line and transfer your current balance to the new line. <a target="_blank" href="https://www.suntrust.com/PersonalBanking/Loans/EquityLinesOfCreditAndLoans/EquityLineOfCredit">Learn More</a> about our Access 3<sup>&reg;</sup> Equity Line.
    <br /><br />
    <strong>Get started:</strong> <a target="_blank" href="https://www.suntrust.com/portal/server.pt?space=Redirect&amp;CommunityID=1805&amp;ui_ProdGroup=IL&amp;ui_ProdSubGroup=EQLN&amp;ui_Product=INETACCX&amp;POPNAC=T">Apply Online</a>, Call <span class="blue">877-748-4059</span>, or stop by your <a target="_blank" href="https://www.suntrust.com/FindUs">local branch</a>.
</div>

脚本代码:

$('#popoverBtn1').popover({
    html: true,
    title: '<a class="close popoverThis">&times;</a>',
    content: $('#popoverContent1').html(),
});
$('#popoverBtn2').popover({
    html: true,
    title: '<a class="close popoverThis">&times;</a>',
    content: $('#popoverContent2').html(),
});
$('#popoverBtn3').popover({
    html: true,
    title: '<a class="close popoverThis">&times;</a>',
    content: $('#popoverContent3').html(),
});

$('.popoverThis').click(function (e) {
    e.stopPropagation();
});

$(document).click(function (e) {
    if (($('.popover').has(e.target).length == 0) || $(e.target).is('.close')) {
        $('.popoverThis').popover('hide');
    }
});

【问题讨论】:

  • 我发现如果您使用弹出框的关闭按钮会出现问题,但如果您再次单击弹出框目标元素关闭则不会出现问题。
  • 在 Linux 上的 Chrome 中测试,我似乎无法重现问题...
  • 是的,isherwood,这似乎是问题所在。不幸的是,我需要在弹出框“关闭 X”上具有与按钮相同的关闭功能。
  • 看看我的解决方案是否适合你。如果没有,请给我一些反馈,我会调查它。谢谢

标签: javascript jquery twitter-bootstrap button popover


【解决方案1】:

这是一种选择:

$('#popoverBtn1').popover({
    html: true,
    title: '<a class="close popoverThis">×</a>',
    content: $('#popoverContent1').html(),
});
$(document).on('click','.close',function (e) {
    $(this).closest('.popover').css('z-index','-1');
    $(this).closest('.popover').prev('button').popover('hide');
});
$('button.popoverThis').on('show.bs.popover', function () {
  $(this).next('.popover').css('z-index','100');
});

例子:

http://www.bootply.com/106588

更新

改用这个:

$(document).on('click','.close',function (e) {
    $(this).closest('.popover').hide();
    $(this).closest('.popover').prev('button').popover('hide');
});

http://www.bootply.com/106678

【讨论】:

  • 谢谢谢谢谢谢!这成功了!在链接处更新。
  • Trevor 我似乎确实在 IE8 中产生了一种奇怪的效果。使用 X 关闭按钮关闭时的弹出框。似乎在页面上仍然可见,但被切断了一点。但是如果你用按钮关闭它们,它们就不会保持可见。关于如何解决这个问题的任何想法?感谢您的所有帮助。
  • @TerriSwiatek 是的,试试这个:好吧,检查我的更新。我会用新链接更新我的答案。让我知道该更新是否对您有用。
  • 非常感谢,你的速度很快!
  • 我刚刚对此进行了更多测试,但关闭“Xs”似乎不适用于移动设备。特别是我的 iPhone 4s。有什么想法吗?再次感谢您的宝贵时间。
【解决方案2】:

尝试改变:

$(document).click(function (e) {
if (($('.popover').has(e.target).length == 0) || $(e.target).is('.close')) {
    $('.popoverThis').popover('hide');
}

});

到:

$(document).click(function (e) {
if (($('.popover').has(e.target).length == 0) || $(e.target).is('.close')) {
    $('.popoverThis').click();
}

});

【讨论】:

  • 这允许我单击下面的按钮,但会显示其他 2 个隐藏的弹出窗口。您可以在上面的链接中看到它的实际效果。不幸的是,这也是不可接受的。
猜你喜欢
  • 2023-03-15
  • 1970-01-01
  • 1970-01-01
  • 2014-04-08
  • 2012-01-29
  • 1970-01-01
  • 2011-11-24
  • 2014-12-28
  • 1970-01-01
相关资源
最近更新 更多