2010-12-21 71 views
0

這裏是我的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; 
    }); 
}); 

這裏是我的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> 

當我的縮略圖,動畫淡入點擊和隱藏的作品,但形象沒有改變......爲什麼?

回答

1

感謝ü@Shurdoof!現在一切正常! 這裏是解決方案:

$('#random_img').attr('src',image); 
0

要改變形象,指定第二個參數attr

$('#random_img').attr('src', image); 

取而代之的是,這將無法工作:

$('#random_img').attr('src') = image; 

Check out the second version of attr here for more info.


您還沒有將src儲存在您的image vari能,但其rel屬性在這裏:

var image = $(this).attr("rel"); 

這應該是:

var image = $(this).attr("src"); 
0
$('#random_img').attr('src') == image; 

應該

$('#random_img').attr('src') = image;