所以我有一个在 NodeJS 上运行并使用 bootstrap 作为前端的 Web 应用程序。我集成了一些 Bootstrap 弹出窗口,它们执行以下操作:
- 当用户点击或点击图像时,将会弹出弹出窗口。
- 用户可以单击任意位置,它将关闭弹出窗口。
当我从台式机或笔记本电脑浏览器打开应用程序时,它们工作正常,但是当我在移动浏览器(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 不会将点击事件绑定(bind)到 html
或 body
。尝试一下这样的事情( 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');
}
});
});
希望这有帮助。
关于javascript - Bootstrap Popover 点击时关闭 : Works fine in desktop browser but not in mobile browser,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30626171/