简体   繁体   中英

Bootstrap 3 Tooltip behave wierd when trigger is 'click' and not working when 'manual'

I'm getting crazy, I try to understood Tooltip behaviour but unsuccessfully.

1. The first issue is when I try to use it in on click event by plugin (button 1) -> if you will go to Fiddle than you will see that function inside of 'content' property is called twice every click... why?

2. I want to use Tooltip bound to an element (button 2) and show it in manual mode but then it's not working at all... why?

HTML

<div class="container">
    <div class="row">
        <div class="col-xs-12">
            <br/>
            <a href="#" class="btn btn-success">I'm working! :-D</a>   <span class="badge b0">0</span>         
            <br/>
        </div>        
    </div>
    <div class="row">
        <div class="col-xs-12">
            <br/>
            <a href="#" class="btn btn-danger">I'm not working! :-(</a>   <span class="badge b1">0</span>         
            <br/>
        </div>
    </div>
</div>

JS

 var i = 0, j = 0; 

 $('.container').popover({
        selector: '.btn-success',
        html: true,
        placement: 'right',
        container: '.container',
        trigger: 'click',            
        content: function(){
            $('.badge.b0').text(j++);
            return 'test';
        }
  });

  $('.container').popover({
        selector: '.btn-danger',
        html: true,
        placement: 'right',
        container: '.container',
        trigger: 'manual',            
        content: 'test'
  });

  $('.container').on('click', '.btn-danger', function(){
        $('.badge.b1').text(i++);
        $(this).popover('show');            
  }); 

FIDDLE

http://jsfiddle.net/gepbmonh/8/

$('#add').click(function () {
     addButton()
 })

var ind = 0;
// adding buttons
function addButton() {
     ind++;
     // creating button
     $button = $('<a href="#"></a>');
     $button.text('I\'m not working! :-( ' + ind);
     $button.addClass('btn btn-danger has_popover');
     $button.attr('data-html', 'true');
     $button.attr('data-placement', 'left');
     $button.attr('data-trigger', 'manual');
     $button.attr('data-content', 'test ' + ind);
     // creating badge  
     $span = $('<span class="badge b' + ind + '">0</span>');

     $wrap = $('<div></div>');   
     $wrap.append($button).append($span);

     // add to the stage
     $('#buttons').append($wrap);
}
//inclick event
$('.container').on('click', '.has_popover', function () {
     // find an appropriately badge
     $badge = $(this).parent().find('.badge');
     // get current value
     var i = $badge.text();
     i = parseInt(i);
     // increase for one
     i++;
     $badge.text(i);
     //showing popover
     $(this).popover('show');
});

1) It isn't called twice every click, it is called once every click, but it is also counting the click that makes it go away, just the text only updates every other click.

2) I'm not really sure what you mean by this, could you explain further and I will edit my post.

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