change the image doesnt work
here is my javasript:
$(function() {
$(".image2").click(function() {
var image = $(this).attr("rel");
$('#random_img').hide();
$('#random_img').fadeIn('slow');
$('#random_img').attr('src') == image;
var image2 = $('开发者_运维问答#random_img').attr('src');
$("#thumb2 a img").removeClass("open");
$("#thumb2 a[rel='" + image2 + "'] img").addClass("open");
return false;
});
});
here is my html:
<div id="image2">
<img id="random_img" src="/documents/templates/projedepo/banner/indigovision.jpg" height="420" width="964" />
</div>
<div id="thumb2">
<a href="#" rel="/documents/templates/projedepo/banner/canon.jpg" class="image2">
<img title="Canon" class="slider_thumb" src="/documents/templates/bilgiteknolojileri/images/t_flash/t1.png" border="0"/></a>
<a href="#" rel="/documents/templates/projedepo/banner/indigovision.jpg" class="image2">
<img title="IndigoVision" class="slider_thumb" src="/documents/templates/bilgiteknolojileri/images/t_flash/t2.png" border="0"/>
</a>
</div>
when i click on a thumbnail, the animation fadeIn and hide works, but the image is not changed...why?
Thank u @Shurdoof! now everything works fine! here is the solution:
$('#random_img').attr('src',image);
To change the image, specify second argument to attr
:
$('#random_img').attr('src', image);
Instead of this which won't work:
$('#random_img').attr('src') = image;
Check out the second version of attr
here for more info.
You are also not storing src
in your image
variable but its rel
attribute here:
var image = $(this).attr("rel");
Which should be:
var image = $(this).attr("src");
Check http://api.jquery.com/attr/
Also, you are using equality operator ==
where you may usually use assignment operator =
. This won't work with .attr
method though..
$('#random_img').attr('src') == image;
should be
$('#random_img').attr('src') = image;
精彩评论