【发布时间】:2013-12-05 10:12:37
【问题描述】:
我有 20 张图片和相同的 20 张不同颜色的图片以相同的名称命名,但第二张带有后缀“_blu”->“google.jpg”,另一张为“google_blu.jpg” 我会做一个鼠标悬停以将其从一个更改为另一个。
我试过这样,但我不知道如何定位图像(我可以说“.hovertondo 类中的每个图像)
jQuery(document).ready(function($) {
$(".hovertondo").css("opacity","1");
$(".hovertondo").hover(function () {
var src = $(this).attr('src');
$(this).attr('src', src.replace('_blu', ''));
$(this).stop().animate({opacity: 0}, "slow");
},function () {$(this).stop().animate({opacity: 1}, "slow");
$(this).attr('src', src.replace('_blu', ''));
});
});
HTML
<div class="conttondodentosofia">
<img src="http://studiodentisticocova.com/img/trattamenti/carie_blu.jpg" />
<div class="hovertondo">Carie</div>
</div>
我用firebug打开它,错误是
"TypeError: $(...).attr(...) is undefined" (谈论这一行 $(this).attr('src', src.replace('_blu', '')) ;)
有人帮助我吗? :) 谢谢!
【问题讨论】:
-
您可以通过获取和设置
this.src而不是使用$(this).attr(src)来简化此操作。