悬停标题标签 [英] Hiding title tags on hover

查看:189
本文介绍了悬停标题标签的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我浏览过以前的问题,其中没有一篇真的对我有用,我检查过Google,我发现的信息似乎很模糊,所以我想我会在这里尝试。

I've looked through previous questions and none of them have really worked for me, i've checked google to and the information I found seems pretty vague, so I thought i'd try here.

任何人都知道/或解决悬停时显示标题标签的问题。我有一系列的链接和图像,将被分配标题标签,但是,其中一些将显示信息,最好不要弹出悬停。

Is anyone aware/or have tackle the problem of title tags displaying on hover. I have a series of links and images that will be assigned title tags, however, some of them will be displaying information that would be better off not popping up on hover.

是否有一个全局函数可以用于将这个应用于所有标题标签?一个例子如下:

Is there a global function I could use to apply this to all manner of title tags? An example would be as follows:

<a href="service.php" title="services for cars" />

如果可能的话,我想停用悬停时显示的标题汽车服务。

If possible I would like to disable the title "services from cars" appearing on hover.

再次感谢。

推荐答案

<a href="service.php" title="services for cars" onmouseover="this.title='';" />

如果您之后需要标题,您可以恢复它:

If you need the title afterwards, you can restore it:

<a href="service.php" title="services for cars" onmouseover="this.setAttribute('org_title', this.title'); this.title='';" onmouseout="this.title = this.getAttribute('org_title');" />

这种方法虽然不是通用的,但它适用于所有的锚, :

This way is not generic though.. to have it applied to all the anchors, have such JavaScript code:

window.onload = function() {
    var links = document.getElementsByTagName("a");
    for (var i = 0; i < links.length; i++) {
        var link = links[i];
        link.onmouseover = function() {
            this.setAttribute("org_title", this.title);
            this.title = "";
        };
        link.onmouseout = function() {
            this.title = this.getAttribute("org_title");
        };
    }
};

现场测试案例

编辑:为更多标签应用相同的标签(例如< img> )首先将代码的核心移动到一个函数中:

to apply same for more tags (e.g. <img>) first move the core of the code to a function:

function DisableToolTip(elements) {
    for (var i = 0; i < elements.length; i++) {
        var element = elements[i];
        element.onmouseover = function() {
            this.setAttribute("org_title", this.title);
            this.title = "";
        };
        element.onmouseout = function() {
            this.title = this.getAttribute("org_title");
        };
    }
}

然后将代码更改为:

window.onload = function() {
    var links = document.getElementsByTagName("a");
    DisableToolTip(links);
    var images = document.getElementsByTagName("img");
    DisableToolTip(images);
};

这篇关于悬停标题标签的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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