单击更改Twitter Bootstrap工具提示内容 [英] Change Twitter Bootstrap Tooltip content on click

查看:92
本文介绍了单击更改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');

这篇关于单击更改Twitter Bootstrap工具提示内容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆