【问题标题】:How to hide the title of an image on hover [duplicate]如何在悬停时隐藏图像的标题[重复]
【发布时间】:2015-06-03 20:53:13
【问题描述】:

在这里,我将拥有图像的标题,并且我需要此标题用于其他目的。但我不希望在图像悬停时显示该标题。尽快回复将不胜感激。提前致谢。

【问题讨论】:

  • 如果你想将标题用于其他目的,为什么不在你的标签中使用用户定义的属性呢?例如user-title=" " 等并将该属性作为 $('anyid').attr('user-title');
  • 也许您应该从标题切换到替代属性?不知道你为什么需要一个标题。

标签: javascript jquery html css image


【解决方案1】:

不要使用 title 属性应用它,而是使用 data 属性。这样就不会调用默认行为,但您仍然可以出于您的目的访问它。

<img data-title="Image Title" ...

【讨论】:

    【解决方案2】:

    如果可以,请将标题移至 data-title,这是一个自定义属性,您可以将其用于标题的其他用途。

    如果你不能,你可以使用这样的js

    $("img").mouseenter(function(){
    
            // Get the current title
            var imgtitle = $(this).attr("title");     
            // Store it in a temporary attribute
            $(this).attr("data-title", imgtitle);     
            // Set the title to nothing so we don't see the tooltips
            $(this).attr("title","");
    
        });
        $(".element").mouseleave(function(){
            // get the attribute back
            var imgTitle = $(this).attr("data-title");
            // Set the title back
            $(this).attr("title","imgtitle ");             
        });
    

    这应该可以解决问题

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-01-10
      • 2012-06-30
      • 1970-01-01
      • 2011-02-09
      • 2017-04-10
      • 2021-12-02
      • 1970-01-01
      • 2010-10-30
      相关资源
      最近更新 更多