使用此显示图像的 alt 标记 - jquery [英] display alt tag for image using this - jquery
本文介绍了使用此显示图像的 alt 标记 - jquery的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
客户希望在悬停时显示 alt 标记文本(并且不能确信它应该是标题,唉).这是据我所知,但我只需要显示悬停的 img 的 alt 标签,而不是全部显示.我尝试删除每个",但它坏了(我知道我不太擅长这个).我该如何解决:
A client wants the alt tag text to appear when hovered (and can't be convinced it should be title, alas). This is as far as I got, but I need only the hovered img's alt tag to display, rather than all of them. I tried removing 'each' but it broke (I know I'm not very good at this). How do I fix it:
$("ul.thumb li img").hover(function() {
$(this).each(function(i, ele) {
$("li").append("<div class=alt>"+$(ele).attr("alt")+"</div>");
$(this).mouseleave(function(event){
$(".alt").css('display','none');
});
});
});
推荐答案
$("ul.thumb li img").each(function() {
$(this).parent('li').append($("<span/>").text($(this).attr("alt")).hide());
}).hover(function(){
$(this).parent('li').children('span').show();
},function(){
$(this).parent('li').children('span').hide();
});
这篇关于使用此显示图像的 alt 标记 - jquery的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文