0

我想在打开新弹出窗口时关闭所有打开的弹出窗口。我试过这样:

$(document).on('click', '.close-pop', function(){
    $('.pop-over').popover('hide');
});

不幸的是,这也会关闭触发关闭操作的弹出窗口。任何想法?谢谢!

按照巴斯的回答,我解决了我的问题如下:

$(document).on('click', '.pop-up', function(){ // each pop link has `.pop-up`, but they all have different ids
    clickid = $(this).attr('id');
    $('.pop-up').each(function(){
    if($(this).attr('id')!=clickid){ $(this).popover('hide');}
    });
});
4

1 回答 1

0

为您的弹出窗口提供相同的类和唯一的 ID。使用如下所示的函数:

javascript

$(function () { 
var clickid;    
$('.popoverlink').each(function(){$(this).popover({trigger:'manual'});});
$('.popoverlink').click(function() {
        if(clickid === $(this).attr('id'))return;
        clickid = $(this).attr('id');
        $('.popoverlink').each(function()
        {
                if($(this).attr('id')!=clickid){ $(this).popover('hide');}
        });

        $(this).popover('show');

    });
});  

html

<div class="well">  
<a href="#" class="popoverlink" id="example" class="btn btn-danger" rel="popover" data-content="It's so simple to create a tooltop for my website!" data-original-title="Twitter Bootstrap Popover">Click for popover</a>  
</div>  

<div class="well">  
<a href="#" class="popoverlink" id="example2" class="btn btn-danger" rel="popover" data-content="It's so simple to create a tooltop for my website!" data-original-title="Twitter Bootstrap Popover">Click for popover</a>  
</div>  

<div class="well">  
<a href="#" class="popoverlink" id="example3" class="btn btn-danger" rel="popover" data-content="It's so simple to create a tooltop for my website!" data-original-title="Twitter Bootstrap Popover">Click for popover</a>  
</div>  
于 2013-05-23T10:36:49.547 回答