Html 是否可以隐藏 href 标题?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/1322839/
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
Is it possible to hide href title?
提问by Johan
采纳答案by jeroen
Supposing you are using an image tag in the a tag, you can just use an alternative title for the image (even a space) and that will overwrite the title of the link when you hover over it.
假设您在 a 标签中使用图像标签,您可以为图像使用替代标题(甚至是空格),当您将鼠标悬停在链接上时,它将覆盖链接的标题。
回答by bobince
How about a nice simple:
一个不错的简单怎么样:
<a href="link.html" title="Titletext"><span title=" ">text</span></a>
(Better, put something actually useful in the nested title.)
(最好在嵌套标题中放一些实际有用的东西。)
回答by fruitwerks
This is really easy with jQuery
使用 jQuery 这真的很容易
$("li.menu-item > a").attr('title', '');
That will remove the title from any a elements of the li class menu-item - of course you can get fancy so they just hide on a mouse over :)
这将从 li 类菜单项的任何 a 元素中删除标题 - 当然你可以花哨,所以它们只是在鼠标悬停时隐藏:)
回答by Lokin
In Regards to the "how about a nice simple" suggestion I've seen listed on several sites, I personally would not suggest this for two reasons.
关于我在几个网站上看到的“一个简单的好东西怎么样”的建议,我个人不建议这样做,原因有两个。
Screen readers and visually impaired users rely on title attributes which are read out loud. I believe this was the initial purpose and reason for them in anchor tags and is a large aspect of USA Gov. Web Accessibility Section 508. I think a screen reader in this instance would read through all the titles; the first one and then the second one which could be very confusing for the visually impaired user. They would not understand why they are hearing two esp if it holds different text. Is it two different anchors they are hearing about? If so, why can they not click or select the other one they hear and keep getting only one web page (as a scenario).
If you place additional text in both title's Google and many other search engines may view this action as black hat seo and could lead your site to getting banned from that search engines listing (aka stuffing), this happened to BMW in Germany by Google already.
屏幕阅读器和视障用户依赖于大声朗读的标题属性。我相信这是它们在锚标签中的最初目的和原因,并且是美国政府 Web Accessibility Section 508 的一个重要方面。我认为在这种情况下,屏幕阅读器会通读所有标题;第一个然后是第二个,这对于视障用户来说可能会非常混乱。他们不明白为什么他们会听到两个 esp,如果它包含不同的文本。他们听到的是两个不同的主播吗?如果是这样,他们为什么不能点击或选择他们听到的另一个网页,并继续只获取一个网页(作为一种场景)。
如果您在标题的 Google 和许多其他搜索引擎中都放置了额外的文字,则可能会将此操作视为黑帽 seo,并可能导致您的网站被禁止出现在该搜索引擎列表中(又名填充),这已经发生在德国的 BMW 上,Google 已经这样做了。
I personally would think the best method is to keep the title attribute as it was meant to function and then use Javascript or css to somehow hide it. These methods would have no impact on screen readers, web crawlers, and visually impaired users.
我个人认为最好的方法是保留 title 属性,因为它应该起作用,然后使用 Javascript 或 css 以某种方式隐藏它。这些方法不会对屏幕阅读器、网络爬虫和视障用户产生影响。
回答by Jim
I got fancy with jquery... ;) I needed this for a portfolio: title-tags for a lightbox but none on mouse-over. This worked for me, thanks for the hint!
我喜欢 jquery... ;) 我需要这个作为投资组合:灯箱的标题标签,但鼠标悬停时没有。这对我有用,谢谢你的提示!
$(function(){
$("li.menu-item > a").hover(function(){
$(this).stop().attr('title', '');},
function(){$(this).stop().attr();
});
});
回答by David says reinstate Monica
// Suppress tooltip display for links that have the classname 'suppress'
var links = document.getElementsByTagName('a');
for (var i = 0; i < links.length; i++) {
if (links[i].className == 'suppress') {
links[i]._title = links[i].title;
links[i].onmouseover = function() {
this.title = '';
}
links[i].onmouseout = function() {
this.title = this._title;
}
}}
To quote Aron Rotteveel's answer from the first dupe linked in my comment to the question (Disabling browser tooltips on links and <abbr>s)
引用Aron Rotteveel从我的评论中链接到该问题的第一个欺骗中的回答(禁用链接和 <abbr>s 上的浏览器工具提示)
回答by Tim S. Van Haren
You don't have to use the title
attribute with Slimbox. See the Multiple Images example near the top of this page: http://code.google.com/p/slimbox/wiki/MooToolsAPI.
您不必在title
Slimbox 中使用该属性。请参阅本页顶部附近的多张图片示例:http: //code.google.com/p/slimbox/wiki/MooToolsAPI。
You can simply remove the title
attribute from your anchor, and pass the title
text (your image's description) to the Slimbox open
function, which you would call using the onclick
event of your anchor.
您可以简单地title
从锚点中删除该属性,并将title
文本(图像的描述)传递给 Slimboxopen
函数,您将使用onclick
锚点的事件调用该函数。
回答by Aldee
the easiest way would be :
最简单的方法是:
after using your slimbox, add the following code below it:
使用您的 slimbox 后,在其下方添加以下代码:
$('*[title]').removeAttr('title');
hope it can help..
希望它可以帮助..
回答by radu.luchian
Using the idea from David Thomas, you can create a more elegant solution using jQuery:
使用 David Thomas 的想法,您可以使用 jQuery 创建一个更优雅的解决方案:
$('[title]').each(function(){
$(this).data('original-title', $(this).attr('title'));
}).hover(
function () {
$(this).attr('title','')
}, function () {
$(this).attr('title',$(this).data('original-title'))
});
回答by Niels Abildgaard
jQuery solution - this should be straight forward:
jQuery 解决方案 - 这应该是直截了当的:
var hiddenTitle; //holds the title of the hovered object
$("li.menu-item > a").hover(function() {
hiddenTitle = $(this).attr('title'); //stores title
$(this).attr('title',''); //removes title
}, function() {
$(this).attr('title',hiddenTitle); //restores title
});