是否可以隐藏href标题?

发布于 2024-08-02 22:39:47 字数 246 浏览 8 评论 0原文

<a href="link.html" title="Titletext">

...是代码。

由于 slimbox,我需要使用 title 属性,但我想要隐藏将鼠标悬停在链接上时显示的标题文本。

有什么想法吗?

<a href="link.html" title="Titletext">

...is the code.

I need to use the title attribute because of slimbox, but I want to hide the title-text that shows up when hovering the mouse over the link.

Any ideas?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(16

谈场末日恋爱 2024-08-09 22:39:47

一个简单的怎么样:(

<a href="link.html" title="Titletext"><span title=" ">text</span></a>

更好的是,在嵌套标题中添加一些实际有用的内容。)

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.)

回梦 2024-08-09 22:39:47

假设您在 a 标签中使用图像标签,则可以为图像使用替代标题(甚至是空格),当您将鼠标悬停在链接上时,该标题将覆盖链接的标题。

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.

十年九夏 2024-08-09 22:39:47

使用 jQuery 这真的很容易,

$("li.menu-item > a").attr('title', '');

它将从 li 类菜单项的任何 a 元素中删除标题 - 当然,您可以很喜欢,所以它们只需将鼠标悬停在上面即可隐藏:)

This is really easy with 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 :)

反差帅 2024-08-09 22:39:47

关于我在几个网站上看到的“一个简单的好主意怎么样”的建议,我个人不会建议这样做,原因有两个。

  1. 屏幕阅读器和视障用户依赖大声朗读的标题属性。我相信这是它们在锚标签中的最初目的和原因,也是美国政府 Web 可访问性第 508 节的一个重要方面。我认为在这种情况下,屏幕阅读器会阅读所有标题;第一个,然后是第二个,这可能会让视障用户感到非常困惑。他们不明白为什么他们会听到两个特别是如果它包含不同的文本。他们听到的是两个不同的主播吗?如果是这样,为什么他们不能单击或选择他们听到的另一个并继续只获得一个网页(作为一种场景)。

  2. 如果您在两个标题的 Google 和许多其他搜索引擎中都放置其他文本,则可能会将此操作视为黑帽 seo,并可能导致您的网站被该搜索引擎列表禁止(又称填充),这种情况发生在德国的宝马身上谷歌已经。

我个人认为最好的方法是保留 title 属性,因为它应该起作用,然后使用 Javascript 或 css 以某种方式隐藏它。这些方法对屏幕阅读器、网络爬虫和视障用户没有影响。

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.

  1. 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).

  2. 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.

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.

み格子的夏天 2024-08-09 22:39:47

我喜欢 jquery...;) 我需要这个来制作作品集:灯箱的标题标签,但鼠标悬停时没有标题标签。这对我有用,感谢您的提示!

$(function(){
    $("li.menu-item > a").hover(function(){
        $(this).stop().attr('title', '');},
        function(){$(this).stop().attr();
        });
});

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!

$(function(){
    $("li.menu-item > a").hover(function(){
        $(this).stop().attr('title', '');},
        function(){$(this).stop().attr();
        });
});
自在安然 2024-08-09 22:39:47
// 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;
        }
    }}

引用 Aron Rotteveel 在我的评论中链接到问题的第一个骗子的回答(禁用链接和 上的浏览​​器工具提示

// 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)

日暮斜阳 2024-08-09 22:39:47

您不必将 title 属性与 Slimbox 一起使用。请参阅本页顶部附近的多个图像示例:http://code.google。 com/p/slimbox/wiki/MooToolsAPI

您只需从锚点中删除 title 属性,然后将 title 文本(图像的描述)传递给 Slimbox open 函数即可将使用锚点的 onclick 事件进行调用。

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.

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.

瑾兮 2024-08-09 22:39:47

最简单的方法是:

使用 slimbox 后,在其下方添加以下代码:

$('*[title]').removeAttr('title');

希望它能有所帮助..

the easiest way would be :

after using your slimbox, add the following code below it:

$('*[title]').removeAttr('title');

hope it can help..

旧伤慢歌 2024-08-09 22:39:47

不能保证,但根据 Slimbox 的工作方式,您也许可以包含标题,然后使用 jQuery 等在页面加载几秒钟后将其删除。假设 Slimbox 索引了 Title 属性并在读入后将其存储在某个位置,那么您可以在发生这种情况后安全地删除它。

No guarantees but depending on how Slimbox works you may be able to include the title then use something like jQuery to remove it a few seconds after page load. Assuming Slimbox indexes the Title attribute and stores it somewhere after reading it in, you may be able to safely remove it after this happens.

风追烟花雨 2024-08-09 22:39:47

用空的 jQuery 工具提示覆盖/覆盖它?

Override/overlay it with an empty jQuery tooltip?

爱的十字路口 2024-08-09 22:39:47

如果您使用jquery,您可以执行以下操作

$("a").mouseover(function(e){ preventdefault();} );

(但尚未测试)

if you are using jquery, you could do following

$("a").mouseover(function(e){ preventdefault();} );

(haven't tested it though)

轻拂→两袖风尘 2024-08-09 22:39:47

难道你不能循环遍历 DOM 中的链接并将 title 属性设置为空字符串吗?

var DOMlinks = document.links;
for(i=0;i<DOMlinks.length;i++){
DOMlinks[i].title = ""
}

Couldn't you just loop through the links in the DOM and set the title attribute to an empty string.

var DOMlinks = document.links;
for(i=0;i<DOMlinks.length;i++){
DOMlinks[i].title = ""
}
独自←快乐 2024-08-09 22:39:47

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
});

jQuery solution - this should be straight forward:

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
});
缺⑴份安定 2024-08-09 22:39:47

利用 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'))
});

Using the idea from David Thomas, you can create a more elegant solution using jQuery:

$('[title]').each(function(){
    $(this).data('original-title', $(this).attr('title'));
}).hover(
    function () { 
        $(this).attr('title','')
    }, function () { 
        $(this).attr('title',$(this).data('original-title'))
});
慕巷 2024-08-09 22:39:47

这是我的 jQuery 解决方案,它可以完成您需要的一切,并保持 title 属性的正确用法。只需根据您的需要更改选择器即可。

/*
 * jQuery remove title browser tooltip
 */
var removeTitleSelector = 'a.removeTitle';
jQuery('body').on('mouseover', removeTitleSelector, function () {
    jQuery(this).data('title', jQuery(this).attr('title'));
    jQuery(this).removeAttr('title');
}).on('mouseout', removeTitleSelector, function () {
    jQuery(this).attr('title', jQuery(this).data('title'));
});

This is my jQuery solution, it does everything you need and keep the correct usage of the title attribute. Simply change the selector according to your needs.

/*
 * jQuery remove title browser tooltip
 */
var removeTitleSelector = 'a.removeTitle';
jQuery('body').on('mouseover', removeTitleSelector, function () {
    jQuery(this).data('title', jQuery(this).attr('title'));
    jQuery(this).removeAttr('title');
}).on('mouseout', removeTitleSelector, function () {
    jQuery(this).attr('title', jQuery(this).data('title'));
});
戈亓 2024-08-09 22:39:47

正如在另一个问题上所读到的那样,我建议将“标题”属性切换为某些“数据标题”,以便残疾用户的屏幕阅读器可以使用它。正如洛金所说,保持网站对受损和残疾用户的可用性也应该是开发时需要关注的问题。

As read on another question, I suggest to switch the "title" attribute to some "data-title" in order to keep it available for screen readers for disabled users. As Lokin said, maintaining the usability of the site to impaired and disabled users should be also something to concern about when developing.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文