twitter-bootstrap rel="tooltip",这是不好的做法吗?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/14511250/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
rel="tooltip", is it bad practice?
提问by Archonic
In the bootstrap documentation for tooltips, it uses <a href="#" rel="tooltip" title="first tooltip">hover over me</a>. Tooltips are just cosmetic though. Not css style but just a bit of JS to change how a title attribute is presented.
在工具提示的引导程序文档中,它使用<a href="#" rel="tooltip" title="first tooltip">hover over me</a>. 工具提示只是装饰性的。不是 css 样式,而是一些 JS 来改变标题属性的呈现方式。
The "rel" attribute is meant to be used to tell a bot (such as google) about the nature of a link. The options are alternate, author, bookmark, help, license, next, nofollow, noreferrer, prefetch, prev, search, and tag.
“rel”属性旨在用于告诉机器人(例如谷歌)有关链接的性质。选项是替代、作者、书签、帮助、许可、下一个、nofollow、noreferrer、预取、上一个、搜索和标记。
Is it not bad practice to use rel = "tooltip"since tooltip is cosmetic, says nothing about the nature of the link, and isn't otherwise bot or browser interpret-able?
rel = "tooltip"因为工具提示是装饰性的,没有说明链接的性质,而且机器人或浏览器不能解释,所以使用这不是坏习惯吗?
采纳答案by Fabian Leutgeb
By using rel="tooltip"your document won't validateby the W3C web standards.
使用rel="tooltip"您的文档不会得到W3C 网络标准的验证。
You will get this error from the W3C validator:
您将从W3C 验证器收到此错误:
Bad value tooltip for attribute rel on element a: Not an absolute IRI. The string tooltip is not a registered keyword or absolute URL.
元素 a 上的属性 rel 的错误值工具提示:不是绝对 IRI。字符串工具提示不是注册关键字或绝对 URL。
It would be better, identifying a tooltiplink with a classlike:<a href="#" class="tooltip" title="first tooltip">hover over me</a>
最好用如下类标识工具提示链接:<a href="#" class="tooltip" title="first tooltip">hover over me</a>
- However, the rel attribute is not used by the browser in any way, as you already mentioned, but it may influence your ranking in search engines. Google suggeststo validate your documents and to "write good, clean HTML".
- The rel attribute may also be interesting for accessibilitytools like screen readers.
- 但是,正如您已经提到的,浏览器不会以任何方式使用 rel 属性,但它可能会影响您在搜索引擎中的排名。Google 建议验证您的文档并“编写好的、干净的 HTML”。
- rel 属性对于屏幕阅读器等辅助工具也可能很有趣。
回答by Kalyan
Or easily you can replace relwith the data-relattribute (which is absolutely valid).
或者您可以轻松地替换rel为data-rel属性(绝对有效)。
Example:
例子:
$("a[data-rel]").tooltip();
回答by Bryan Ash
The Bootstrap documentationsuggests using data-toggle="tooltip", e.g.:
Bootstrap文档建议使用data-toggle="tooltip",例如:
<button type="button" class="btn btn-default" data-toggle="tooltip" data-placement="left" title="Tooltip on left">Tooltip on left</button>
and enabling them with:
并通过以下方式启用它们:
$(function () {
$('[data-toggle="tooltip"]').tooltip()
})

