使用jQuery隐藏本机工具提示 [英] Hide native tooltip using jQuery

查看:80
本文介绍了使用jQuery隐藏本机工具提示的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当用户将鼠标悬停在具有title属性的锚标记上时,是否可以隐藏本机工具提示操作?我不想删除它,只是不显示讨厌的黄色框,它是默认的工具提示操作.

Is there a way to hide the native tooltip action when a user hovers over a anchor tag with a title attribute? I don't want to remove it just don't display the nasty yellow box that is the default tooltip action.

更新:

在阅读了其他几篇文章之后,我认为我无法隐藏本机工具提示操作的title属性,但是我试图在这里跳出框框.我可以在锚标记中使用其他属性代替title属性,并且仍然保留有效的页面吗?

After reading a couple of other posts I don't think I can hide the title attribute for the native tooltip action, but I'm trying to think outside of the box here. Could I use another attribute instead of the title attribute inside the anchor tag and still keep a valid page???

除非有人能弄清楚如何为onclick事件添加回标题属性,否则删除标题属性值不是一个选择吗?

Removing the title attribute value is not an option unless someone can figure out how to add it back for a onclick event?

下面的工作代码

$('[title]').each( function() {
    var $this = $(this);
    $this.data('title',$this.attr('title'));
    $this.removeAttr('title');
});

$('a').click( function() {
    var $this = $(this);
    var title = $this.data('title');
    ... do your other stuff...
});

推荐答案

显然,title属性不属于常规事件处理程序.无论如何,我的原始答案没有用,尽管我会继续研究它是否可以使它起作用.如果您需要保留title属性但不希望弹出效果(如注释中所示),则将title属性存储在元素的数据中,然后从那里使用它.

Apparently the title attribute doesn't fall under the normal event handler. Anyway, my original answer didn't work, though I'll keep playing with it to see if I can get it to work. If you need to retain the title attribute but don't want the popup effect, as indicated in your comments, then store the title attribute in the element's data and use it from there.

$('[title]').each( function() {
    var $this = $(this);
    $this.data('title',$this.attr('title'));
    $this.removeAttr('title');
});

$('a').click( function() {
    var $this = $(this);
    var title = $this.data('title');
    ... do your other stuff...
});

原始答案:

为每个具有标题的元素提供一个特定的悬停在处理程序上,以防止执行默认操作.

Give every element that has a title a specific hover over handler that prevents the default action.

$('[title]').hover(
   function(e) {
       e.preventDefault();
   },
   function() { }
);

除非经过测试,否则似乎无法正常工作.

这篇关于使用jQuery隐藏本机工具提示的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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