admin管理员组

文章数量:1324848

I have this function setup

var $this = $(this);
if (msg == null) { 
    $this.tooltip('destroy');

}
else
{
    $this.tooltip({'title': msg, 'placement': 'right', 'trigger': 'manual'});
    $this.tooltip('show');
}

The tooltip shows up fine, the the destroy line throws an error data[option] is not a function. If I change it to tooltip('hide') the tooltip hides itself, I just can't get it to remove itself. Can anyone help me sort this out?

I have this function setup

var $this = $(this);
if (msg == null) { 
    $this.tooltip('destroy');

}
else
{
    $this.tooltip({'title': msg, 'placement': 'right', 'trigger': 'manual'});
    $this.tooltip('show');
}

The tooltip shows up fine, the the destroy line throws an error data[option] is not a function. If I change it to tooltip('hide') the tooltip hides itself, I just can't get it to remove itself. Can anyone help me sort this out?

Share Improve this question edited Sep 26, 2013 at 12:09 Anshad Vattapoyil 23.5k19 gold badges90 silver badges134 bronze badges asked Sep 26, 2013 at 11:59 TMHTMH 6,2468 gold badges55 silver badges89 bronze badges
Add a ment  | 

3 Answers 3

Reset to default 3

If you didn't make a typo check if you use the latest version of Bootstrap's javascript plugins.

tooltip.js contains:

  // TOOLTIP PLUGIN DEFINITION
  // =========================

  var old = $.fn.tooltip

  $.fn.tooltip = function (option) {
    return this.each(function () {
      var $this   = $(this)
      var data    = $this.data('bs.tooltip')
      var options = typeof option == 'object' && option
      if (!data) $this.data('bs.tooltip', (data = new Tooltip(this, options)))
      if (typeof option == 'string') data[option]()
    })
  }

In the case of .tooltip('destroy'); The line if (typeof option == 'string') data[option]() gives the error you mention if Tooltip.prototype.destroy not exists.

I fix it by loading jquery-ui.min.js after bootstrap.min.js

$this.tooltip('destroy'); //it use Bootsrap tooltip

Try call jQuery

$(this).$(jQuery).tooltip('destroy');


$.ui.tooltip()

or replace function

$.fn.tooltip = jQuery.ui.tooltip;

本文标签: javascriptBootstrap Tooltip dataoption is not a functionStack Overflow