Bootstrap Popover 点击时关闭:在桌面浏览器中工作正常,但在移动浏览器中不行

2024-05-07

所以我有一个在 NodeJS 上运行并使用 bootstrap 作为前端的 Web 应用程序。我集成了一些引导程序弹出窗口,它们执行以下操作:

  1. 当用户单击或点击图像时,它将弹出弹出窗口。
  2. 用户可以单击任意位置,它将关闭弹出窗口。

当我从台式机或笔记本电脑浏览器打开应用程序时,它们工作正常,但是当我在移动浏览器(iPhone 上的 safari)上打开应用程序(使用计算机的 IP 地址)时,弹出窗口不会在单击时消失。这里有什么问题?我错过了什么吗?这是代码:

<img src='/images/question.png' tabindex="0" role="button" data-trigger="focus" height="10" width="10" data-toggle="popover" title="Daily Hub Activity" data-content="Lorem ipsum blablabla." animation="true" data-placement="bottom">

我相信iOS不会将点击事件绑定到html or body。尝试一下这样的事情(单击外部时关闭 Twitter Bootstrap 弹出窗口 http://mattlockyer.com/2013/04/08/close-a-twitter-bootstrap-popover-when-clicking-outside/):

$('[data-toggle="popover"]').popover();

$('body').on('click', function (e) {
    $('[data-toggle="popover"]').each(function () {
        //the 'is' for buttons that trigger popups
        //the 'has' for icons within a button that triggers a popup
        if (!$(this).is(e.target) && $(this).has(e.target).length === 0 && $('.popover').has(e.target).length === 0) {
            $(this).popover('hide');
        }
    });
});

希望这可以帮助。

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

Bootstrap Popover 点击时关闭:在桌面浏览器中工作正常,但在移动浏览器中不行 的相关文章

随机推荐