How to update bootstrap popover text?

后端 未结 9 751
长发绾君心
长发绾君心 2020-12-07 20:31

I am using bootstrap-popover to show a message beside an element.

If I want to show different text in the popover after the first time, the text does not change. Re

相关标签:
9条回答
  • 2020-12-07 20:51

    I found Bootstrap popover content cannot changed dynamically which introduces the setContent function. My code (hopefully helpful to someone) is therefore:

    (Noting that jquery data() isn't so good at setting as it is getting)

    // Update basket
    current = $('#basketPopover').data('content');
    newbasket = current.replace(/\d+/i,parseInt(data));
    
    $('#basketPopover').attr('data-content',newbasket);
    $('#basketPopover').setContent();
    $('#basketPopover').$tip.addClass(popover.options.placement);
    
    0 讨论(0)
  • 2020-12-07 20:53

    On Boostrap 4 it is just one line:

    $("#your-element").attr("data-content", "your new popover content")
    
    0 讨论(0)
  • 2020-12-07 20:58

    Hiya please see working demo here: http://jsfiddle.net/4g3Py/1/

    I have made the changes to get your desired outcome. :)

    I reckon you already know what you are doing but some example recommendations from my end as follows for sample: http://dl.dropbox.com/u/74874/test_scripts/popover/index.html# - sharing this link to give you idea for different link with different pop-over if you will see the source notice attribute data-content but what you wanted is working by the following changes.

    Have a nice one and hope this helps. D'uh don't forget to up vote and accept the answer :)

    Jquery Code

    var i = 0;
    $('a#test').click(function() {
        i += 1;
    
        $('a#test').popover({
            trigger: 'manual',
            placement: 'right',
            content: function() {
               var message = "Count is" + i;
                 return message;
            }
        });
        $('a#test').popover("show");
    
    });​
    

    HTML

    <a id="test">Click me</a>
    ​
    
    0 讨论(0)
提交回复
热议问题