简体   繁体   中英

Loading dynamic content into Bootstrap Popover after form submit

I'm trying to load content dynamically into a Bootstrap popover. When the form is submitted I can alert the value; that's working correctly. What I can't do is get the content of #popover-thanks to load in the popover, replacing the form with a thank you message.

// show the popover
$('#btn').popover({
    html : true,
    placement: 'top',
    content: function() {
        return $('#popover-form').html();
    }
}); 

// form has been submitted
$(document).on('click', '#submit', function() {

    var value = $('#value').val();

    alert(value);

    $('#btn').popover({ 
        html : true,
        content: function() {
            return $('#popover-thanks').html();
        }
    });
});

i think you must Destroy the first popover to be able to make new one on same element:

$( '#btn' ).popover('destroy');

http://getbootstrap.com/javascript/#popovers-usage

  • Another solution, you can get the popover id (after show) like that:

     var popoverID = $( '#btn' ).attr("aria-describedby"); // = 'popover123456' (random number) 

replace the content ( http://getbootstrap.com/javascript/#popovers ), and then show it:

$( '#btn' ).popover('show');

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM