如何使用jQuery在浏览器中禁用工具提示? [英] How to disable tooltip in the browser with jQuery?

查看:232
本文介绍了如何使用jQuery在浏览器中禁用工具提示?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当将鼠标悬停在已填充属性title的元素上时,是否有办法禁用浏览器工具提示?请注意,我不想删除标题内容。
以下是要求的代码:

Is there a way to disable browser tooltip from displaying when hovering over elements that have attribute 'title' populated? Note that I don't want to remove title content. Here is the code are requested:

  $(document).ready(function() {
     $('a.clickableSticky').cluetip({
         splitTitle: '|',
         showTitle: false,
         titleAttribute: 'description',
         activation: 'click',
         sticky: true,
         arrows: true,
         closePosition: 'title'
     });
 });

和asp.net

  <ItemTemplate>
     <a class="clickableSticky" href="#"
     title=' <%#((Limit)Container.DataItem).Tip %>'>
     <img src="..\App_Themes\default\images\icons\information.png"/>
     </a>

 </ItemTemplate>


推荐答案

您可以删除标题页面加载时的属性。

You could remove the title attribute on page load.

$(document).ready(function() {
    $('[title]').removeAttr('title');
});

如果以后需要使用标题,可以将其存储在元素的jQuery中 data()

If you need to use the title later, you can store it in the element's jQuery data().

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

另一种选择是更改标题的名称属性为 aTitle ,或浏览器会忽略的其他内容,然后更新任何JavaScript以读取新属性名称而不是 title

Another option is to change the name of the title attribute to aTitle, or something else that the browser would ignore, and then update any JavaScript to read the new attribute name instead of title.

更新:

一个有趣的想法,你可以当悬停在元素上时,使用是懒洋洋地删除标题。当用户将元素悬停时,您可以将标题值重新设置。

An interesting idea you could use is to "lazily" remove the title when hovering over an element. When the user hovers off the element, you can then put the title value back.

这并不像应该的那样简单,因为IE没有正确删除如果将title属性设置为 null 或删除title属性,则悬停事件上的工具提示。但是,如果在悬停时将工具提示设置为空字符串(),它将从包括Internet Explorer在内的所有浏览器中删除工具提示。

This isn't as straightforward as it should be because IE doesn't correctly remove the tooltip on the hover event if you set the title attribute to null or remove the title attribute. However, if you set the tooltip to an empty string ("") on hover, it will remove the tooltip from all browsers including Internet Explorer.

您可以使用我上面提到的方法将title属性存储在jQuery的 data(...)方法中然后将其放回 mouseout

You can use the method I mentioned above to store the title attribute in jQuery's data(...) method and then put it back on mouseout.

$(document).ready(function() {
    $('[title]').mouseover(function () {
        $this = $(this);
        $this.data('title', $this.attr('title'));
        // Using null here wouldn't work in IE, but empty string will work just fine.
        $this.attr('title', '');
    }).mouseout(function () {
        $this = $(this);
        $this.attr('title', $this.data('title'));
    });
});

这篇关于如何使用jQuery在浏览器中禁用工具提示?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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