2012-07-03 63 views
1

我在寫一個簡單的腳本來替換兩個圖像。第一個交換罰款,但第二個出於某種原因不會開火。這很簡單,我錯過了。也許'div.singleTint img'選擇器?有人可以看看並仔細檢查我的作品嗎?爲什麼我的jQuery選擇器不工作?

這裏是我的HTML:

<div id="beerGlassOverlay"> 
    <img src="<?php bloginfo('template_directory'); ?>/images/beerOverlay.png" class="glassreplace"> 
</div> 

<li class="image-rollover"> 
    <a href="http://brasco.co/Mims/meet-the-breweries/miller-beers/" target="_blank"> 
     <img width="177" height="186" src="http://brasco.co/Mims/wp-content/uploads/2012/05/miller1.png" class="attachment-full wp-post-image" alt="miller" title="miller" /> 
    </a> 
    <div class="singleTint"> 
     <img width="279" height="524" src="http://brasco.co/Mims/wp-content/uploads/shrekBeer.png" class="attachment-full" alt="shrekBeer" title="shrekBeer" /> 
    </div><!-- End singleTint--> 
</li> 

這裏是我的jQuery:

$('li.image-rollover').mouseover(function() { 
$('img.glassreplace').attr({//Change the src and size info on hover   
    src: ('div.singleTint img', this).src, 
    width: '100%', 
    height: '100%' 
    }); 
});` 
+2

你錯過了'$'的'源:( 'DIV ...'雙組分應該是'$(' div.singleTint IMG')' – NoLifeKing

回答

7

改變這一點:

src: ('div.singleTint img', this).src, 

到:

src: $('div.singleTint img', this).attr('src'), 
+0

感謝你,解決了我的問題了!。不勝感激! – TripsLeft

0

src: ('div.singleTint img', this).src,應該成爲src: $('div.singleTint > img', this).attr("src"),

(我已經添加子選擇 - >

0

你缺少你的代碼($)的第三行jQuery對象引用?

$('li.image-rollover').mouseover(function() { 
$('img.glassreplace').attr({//Change the src and size info on hover   
    src: $('div.singleTint img', this).src, //Added the jQuery object in front of the parenthesis. 
    width: '100%', 
    height: '100%' 
    }); 
}); 
相關問題