使用bootstrap popover,现在我试图得到这个代码点击外面的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'); } }); });
但是当我使用这个部分时,我可以关闭popover,但是我不能点击其他按钮,任何人都知道我该怎么做
所有按钮:
<a href="#" class="btn btn-xs btn-primary" data-toggle="popover">This opens popover</a> <a href="#" class="btn btn-xs btn-primary">Other link</a> <- Doesn't work <a href="#" class="btn btn-xs btn-primary">Other link</a> <- Doesn't work
解决方法
我发现这个:
http://bootply.com/99372
$('body').on('click',function (e) { $('[data-toggle=popover]').each(function () { // hide any open popovers when the anywhere else in the body is clicked if (!$(this).is(e.target) && $(this).has(e.target).length === 0 && $('.popover').has(e.target).length === 0) { $(this).popover('hide'); } }); });
几乎和你一样的代码
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。