我目前调用一个脚本来动态地向我的popover添加内容,但是当用户再次单击以关闭它时,我不需要进行此调用.是否可以获得状态并在可见时将其关闭?
这是我到目前为止:
$('.kNownissue').on('click',function() {
var info = $(this).attr('id').substr(5).split(':');
var el = $(this);
// How do I check to see if the popover is visible
// so I can simply close it and exit?
$.post('functions/get_kNown_issues.PHP?tcid='+info[0]+'&tcdate=' + info[1],function(data) {
if (data.st) {
el.attr('data-content',data.issue);
el.popover('toggle');
}
},"json");
});
解决方法
要避免搜索动态插入的标记,您可以执行以下操作:
在Bootstrap 2中:
var $element = $('.element-you-added-popup-to')
$element.data().popover.tip().hasClass('in')
// Or if you used '.tooltip()' instead of '.popover()'
$element.data().tooltip.tip().hasClass('in')
在Bootstrap 3中:
$element.data()['bs.popover'].tip().hasClass('in')
$element.data()['bs.tooltip'].tip().hasClass('in')