问题描述
我在一个锚元素上有一个工具提示,它在点击时发送一个 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.
更短的方法:
$(element).attr('title', 'NEW_TITLE')
.tooltip('fixTitle')
.tooltip('show');
这篇关于单击时更改 Twitter Bootstrap 工具提示内容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!