在这里,我将获得图像的标题,我需要此标题用于其他目的。但我不希望在悬停图像时显示该标题。更快的回复将不胜感激。提前谢谢。
答案 0 :(得分:3)
不要使用title属性应用它,但要使用data属性。这样就不会调用默认行为,但您仍然可以为了您的目的访问它。
<img data-title="Image Title" ...
答案 1 :(得分:0)
如果可以,请将标题移至数据标题,这是一个自定义属性,可用于标题的其他用途。
如果你不能,你可以使用像这样的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 ");
});
应该做的伎俩