单击更改Twitter Bootstrap工具提示内容
我在锚点元素上有一个工具提示,该提示在点击时发送AJAX请求.该元素具有工具提示(来自Twitter Bootstrap).我希望当AJAX请求成功返回时更改工具提示内容.启动后如何操作工具提示?
I have a tooltip on an anchor element, that sends an AJAX request on click. This element has a tooltip (from Twitter Bootstrap). I want the tooltip content to change when the AJAX request returns successfully. How can I manipulate the tooltip after initiation?
今天在阅读源代码时就发现了这一点.因此,$.tooltip(string)
调用Tooltip
类中的任何函数.并且,如果您查看Tooltip.fixTitle
,它将获取data-original-title
属性并用其替换标题值.
Just found this today whilst reading the source code. So $.tooltip(string)
calls any function within the Tooltip
class. And if you look at Tooltip.fixTitle
, it fetches the data-original-title
attribute and replaces the title value with it.
所以我们只需:
$(element).tooltip('hide')
.attr('data-original-title', newValue)
.tooltip('fixTitle')
.tooltip('show');
肯定会更新标题,它是工具提示中的值.
and sure enough, it updates the title, which is the value inside the tooltip.
另一种方式(请参见下面的@lukmdo评论)
Another way (see @lukmdo comment below):
$(element).attr('title', 'NEW_TITLE')
.tooltip('fixTitle')
.tooltip('show');