简体   繁体   English

如何将 Twitter Bootstrap 工具提示应用于包裹在<span>.</span>

[英]How to apply a Twitter Bootstrap tooltip to text wrapped in a <span>?

Apparently you can add a Twitter Bootstrap tooltip to any element that has the .tooltip class, like so:显然,您可以向任何具有.tooltip类的元素添加 Twitter Bootstrap工具提示,如下所示:

$(document).ready(function() {
    $("a[rel='tooltip'], .tooltip").tooltip();
});

However, adding this class to a span tag does not seem to work.但是,将此类添加到 span 标记似乎不起作用。 Example:例子:

<p>1 + 1 = <span class="tooltip" title="Wooo!">2</span></p>

Only links seem to work with tooltips.只有链接似乎与工具提示一起使用。 Example:例子:

<p>2 + 2 = <a href="#" rel="tooltip" title="Wooo!">4</a></p>

Here's a jsFiddle to demonstrate: http://jsfiddle.net/ZznzE/这是一个 jsFiddle 来演示: http : //jsfiddle.net/ZznzE/

So how can I display a tooltip for text wrapped in a span?那么如何为包裹在跨度中的文本显示工具提示?

You don't need a class="tooltip" , but a rel="tooltip"您不需要class="tooltip" ,而是rel="tooltip"

Like this:像这样:

<p>1 + 1 = <span rel="tooltip" title="Tip 1">2</span></p>

I updated your fiddle and it works fine now: http://jsfiddle.net/Xz2e7/1/我更新了你的小提琴,现在工作正常: http : //jsfiddle.net/Xz2e7/1/

I also added a cursor: pointer to the CSS on the span tag.我还添加了一个cursor: pointer span 标签上 CSS 的cursor: pointer For usability this is better, so people know where there is interaction on the page.为了可用性,这更好,所以人们知道页面上哪里有交互。

Edit:编辑:

The tooltip class is not meant for using like you want to use it.工具提示类并不意味着像您想使用它那样使用。 the tooltip class is taking care of the tooltip itself (making it invisible when not hovering for example).工具提示类正在处理工具提示本身(例如,在不悬停时使其不可见)。

Try this: http://jsfiddle.net/Xz2e7/3/试试这个: http : //jsfiddle.net/Xz2e7/3/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM