Bootstrap工具提示数据切换 [英] Bootstrap tooltip data-toggle

查看:100
本文介绍了Bootstrap工具提示数据切换的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Bootstrap文档页面中,工具提示的签名为:

In the Bootstrap documentation page, the tooltip has a signature of:

<a href="#" data-toggle="tooltip" title="first tooltip">hover over me</a>

数据切换属性在这种情况下的作用是什么?

What does the "data-toggle" attribute do in this scenario?

我知道它对标签很有用,但我看不出它可以为工具提示带来什么用处。

I know it's useful for tabs but I don't see what usefulness it can bring to tooltips.

Chris,

工具提示必须明确初始化,如下所示:

The tooltip has to be initialized explicitly as in:

$(document).ready(function(){
    $(".link").tooltip();
});

假设a标签有一个链接类。 data-toggle属性对于工具提示无法正常运行不是必需的。但是你提到过Bootstrap JavaScript文件可以识别某些东西是否是工具提示。因此,省略数据切换仍然使工具提示工作(只要有明确的初始化)似乎没有意义。你能进一步解释一下吗?

Assuming that the "a" tag has a class of "link". The "data-toggle" attribute is not mandatory for the tooltip to function correctly. But you mentioned that it is for the Bootstrap JavaScript file to recognize if something is a tooltip. So it doesn't seem to make sense that omitting "data-toggle" still makes the tooltip work (as long as there is the explicit initialization). Could you explain further?

编辑#2:

在阅读了一些GitHub问题页后,我想我有得出以下结论(这是我最好的猜测)。

After reading some GitHub issue pages, I think I have come to the following conclusion (which is my best guess).

最初,在较早版本的Bootstrap中,工具提示签名是:

Originally, in older versions of Bootstrap, the tooltip signature was:

<a href="#" rel="tooltip" title="first tooltip">hover over me</a>
...
<a href="#" rel="tooltip" title="first tooltip">hover over me again!</a>

开发商可以这样做:

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

一次激活所有工具提示(因为每个工具提示需要初始化到工作)。换句话说,它只是一种标识所有工具提示的便捷方式,因此您可以使用jQuery激活所有工具提示。

To activate all tooltips at once (since each tooltip requires an initialization to work). In other words, it was just a convenient way to identity all the tooltips so that you can use jQuery to activate all of them.

但是rel =tooltip没有验证HTML5,因此人们开始建议使用data-toggle =tooltip,因为Bootstrap已经使用数据切换其他组件和数据 - *在HTML5中有效。

But rel="tooltip" did not validate against HTML5, so folks started suggesting using data-toggle="tooltip" because Bootstrap already uses data-toggle for other components and data-* is valid in HTML5.

因此,我的猜测是数据toggle =tooltip没有特殊的语义含义或目的,除了提供一种方便的方式来识别所有工具提示。

Thus, my guess is that there is no special semantic meaning or purpose for data-toggle="tooltip" other than to provide a convenient way to identity all tooltips.

注意您还可以使用ID或类识别工具提示,但为什么不一次激活所有工具提示(修辞问题)?

Note that you could also identity the tooltips using ID or class, but why not activate all tooltips at once (rhetorical question)?

推荐答案

在阅读了一些GitHub问题页面之后,我想我得出了以下结论(这是我最好的猜测)。

After reading some GitHub issue pages, I think I have come to the following conclusion (which is my best guess).

最初,在旧版本的Bootstrap中,工具提示签名是:

Originally, in older versions of Bootstrap, the tooltip signature was:

<a href="#" rel="tooltip" title="first tooltip">hover over me</a>
...
<a href="#" rel="tooltip" title="first tooltip">hover over me again!</a>

开发商可以这样做:

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

一次激活所有工具提示(因为每个工具提示都需要初始化才能工作)。换句话说,它只是一种识别所有工具提示的便捷方式,因此您可以使用jQuery激活所有工具提示。

To activate all tooltips at once (since each tooltip requires an initialization to work). In other words, it was just a convenient way to identify all the tooltips so that you can use jQuery to activate all of them.

但是rel =tooltip没有验证HTML5,因此人们开始建议使用data-toggle =tooltip,因为Bootstrap已经使用数据切换其他组件和数据 - *在HTML5中有效。

But rel="tooltip" did not validate against HTML5, so folks started suggesting using data-toggle="tooltip" because Bootstrap already uses data-toggle for other components and data-* is valid in HTML5.

因此,我的猜测是数据toggle =tooltip没有特殊的语义含义或目的,除了提供一种方便的方式来识别所有工具提示。

Thus, my guess is that there is no special semantic meaning or purpose for data-toggle="tooltip" other than to provide a convenient way to identity all tooltips.

注意您还可以使用ID或类识别工具提示,但为什么不一次激活所有工具提示(修辞问题)?

Note that you could also identify the tooltips using ID or class, but why not activate all tooltips at once (rhetorical question)?

这篇关于Bootstrap工具提示数据切换的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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