Bootstrap popover content cannot changed dynamically

后端 未结 14 2290
旧时难觅i
旧时难觅i 2020-11-29 22:40

I use the code as follows:

$(\".reply\").popover({
  content: \"Loading...\",
  placement: \"bottom\"
});

$(\".reply\").popover(\"toggle\");
14条回答
  •  生来不讨喜
    2020-11-29 23:27

    If you grab the popover instance like this:

    var popover = $('.reply').data('bs.popover');
    

    Then, to redraw the popover, use the .setContent() method:

    popover.setContent();
    

    I found out browsing the source: https://github.com/twitter/bootstrap/blob/master/js/popover.js

    So, in your example, try:

    thisVal.attr('data-content',data).data('bs.popover').setContent();
    

    Update

    The setContent() method also removes the placement class, so you should do:

    var popover = thisVal.attr('data-content',data).data('bs.popover');
    popover.setContent();
    popover.$tip.addClass(popover.options.placement);
    

    Demo: http://jsfiddle.net/44RvK

提交回复
热议问题