Wordpress 删除工具提示

Wordpress 删除工具提示,wordpress,tooltip,Wordpress,Tooltip,有没有办法禁用鼠标悬停在图像上时浏览器中显示的默认工具提示?这不需要删除title或alt标记。另一个选项是,是否可以使工具提示显示特定图像类型(如JPG)的特定文本和不同图像类型(如PNG)的另一文本?默认情况下,大多数浏览器中的title属性用作悬停文本。我看到删除它们的唯一方法是删除title属性。JavaScript将能够做到这一点。我确信有一种纯粹的DOM方法可以做到这一点,但我使用了一个小jQuery: $(function() { // when the document beco

有没有办法禁用鼠标悬停在图像上时浏览器中显示的默认工具提示?这不需要删除title或alt标记。另一个选项是,是否可以使工具提示显示特定图像类型(如JPG)的特定文本和不同图像类型(如PNG)的另一文本?

默认情况下,大多数浏览器中的
title
属性用作悬停文本。我看到删除它们的唯一方法是删除title属性。JavaScript将能够做到这一点。我确信有一种纯粹的DOM方法可以做到这一点,但我使用了一个小jQuery:

$(function() { // when the document becomes ready for manipulation
  $("[title]").removeAttr('title'); // removes title from all things that have title
  // your other options:
  // all images who's src ends in .jpg       
  $("img[src$=.jpg]").attr('title','JPG Image'); 
  // all images who's src ends in .png 
  $("img[src$=.png]").attr('title','PNG Image'); 
}
如果需要在页面上粘贴此代码,我建议创建一个包含此代码的
site.js
文件。然后你需要告诉你的HTML页面去加载它。您应该有一些主站点模板文件(它可能已经有jQuery-如果是这样,请跳过jQuery的包含:

<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js" type="text/javascript"> </script>
<script type="text/javascript" src="/js/site.js"> </script>

请原谅我的无知,但是如果我使用wordpress博客,我应该在哪里添加上面的代码?你可以通过调用
wp\u enqueue\u脚本('jquery')强制wordpress使用随它一起发布的jquery
开始生成内容之前的某个地方。好的,将工具提示中可能出现的字符限制为零或最多10个怎么样?
 $("[title]").each(function() {
    var $this = $(this); // shortcut for later
    var title = $this.attr('title'); // get the title attribute
    // if the length of our title was 10 characters or more, shorten it and set:
    if (title.length>10) {
      $this.attr('title', title.substring(0,10));
    }
 });