简体   繁体   English

将鼠标悬停在图像上时删除图像标题

[英]Remove image title when mouse hover on the image

I am using lytebox for my image gallery. 我将lytebox用于图片库。 It works great except when a user hovers on images, there will be texts with html tags shown on the browser. 除非用户将鼠标悬停在图像上,否则浏览器上将显示带有html标签的文本,这非常有用。

ex: 例如:

<h1>This is the first image </h1>
<p>The image desc<p>

I need the title attribute for my image gallery but don't want it to show when the user hovesr the image. 我需要我的图片库的title属性,但不希望在用户浏览图像时显示该属性。 Is that possible? 那可能吗? Thanks for the help. 谢谢您的帮助。

var imgTitle;

$("img").hover(function(){
    imgTitle = $(this).attr("title");
    $(this).removeAttr("title");
}, function(){
   $(this).attr("title", imgTitle);
});

I think you'd have to do something like: 我认为您必须执行以下操作:

$('#slideshow img').hover(function() {
    $(this).data('title', $(this).attr('title'));
    $(this).attr('title', '');
}, function() {
    $(this).attr('title', $(this).data('title'));
});​

Demo: http://jsfiddle.net/lucuma/cX5MD/ 演示: http : //jsfiddle.net/lucuma/cX5MD/

You won't see the title on the img's but if you inspect them you'll see they are still there. 您不会在img上看到标题,但如果检查它们,您会发现它们仍然存在。

You could also use jQuery removeAttr and attr instead of setting it to empty string. 您也可以使用jQuery removeAttrattr来代替将其设置为空字符串。

这样很简单

$('img').removeAttr('title');

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM