How can I close / dismiss Bootstrap Popover when clicking the popover trigger element?

后端 未结 4 1463
无人及你
无人及你 2020-12-28 09:14

jsFiddle: http://jsfiddle.net/kAYyR/

Screenshot:

Here\'s what works:

  1. Open popover on button click
  2. Close popo
相关标签:
4条回答
  • 2020-12-28 09:35

    it can simply done by using this code

    <div id='content'>something here</div>
     $('[data-toggle=popover]').popover({
            html: true,
            content: function () {
                return $('#content').html();
            }
        }).click(function (e) {
            $('[data-toggle=popover]').not(this).popover('hide');
        });
    
    0 讨论(0)
  • 2020-12-28 09:36

    Do you want work like this ?

    http://jsfiddle.net/kAYyR/3/

    $('#popoverId').popover({
        html: true,
        title: 'Popover Title<a class="close" href="#");">&times;</a>',
        content: $('#popoverContent').html(),
    });
    
    $('#popoverId').click(function (e) {
        e.stopPropagation();
    });
    
    $(document).click(function (e) {
        if (($('.popover').has(e.target).length == 0) || $(e.target).is('.close')) {
            $('#popoverId').popover('hide');
        }
    });
    
    0 讨论(0)
  • 2020-12-28 09:39

    This simple code will hide all popovers on the page $('.popover').popover('hide');

    0 讨论(0)
  • 2020-12-28 09:50

    I use this:

        $('[data-toggle="popover"]').popover({html: true, container: 'body'});
    
        $('[data-toggle="popover"]').click(function (e) {
            e.preventDefault();
            $('[data-toggle="popover"]').not(this).popover('hide');
            $(this).popover('toggle');
        });
    
        $(document).click(function (e) {
            if ($(e.target).parent().find('[data-toggle="popover"]').length > 0) {
                $('[data-toggle="popover"]').popover('hide');
            }
        });
    
    0 讨论(0)
提交回复
热议问题