2014-04-01 118 views
18

我有一些div的圖像,當我點擊這些圖像時,我想讓另一個div打開,並點擊了該圖像。將圖像src設置爲另一個圖像jquery

JS

$('.examples img').click(function() { 
    var loc = $(this).attr("src"); 
    $('#image-zoom').attr("src",loc); 
}); 

HTML

<div class="container examples" > 
    <div id="image-zoom"> 
     <img class="img-thumbnail zoom" src="" alt="dental"> 
    </div> 
    <div class="row"> 
     <div class="col-sm-12"> 
      <img id="zoom" class="img-thumbnail zoom" src="images/01.png" alt="dental"> 
      <img class="img-thumbnail zoom" src="images/02.png" alt="dental"> 
      <img class="img-thumbnail zoom" src="images/03.png" alt="dental"> 
     </div> 
    </div> 

    <div class="row"> 
     <div class="col-sm-12"> 
      <img class="img-thumbnail zoom" src="images/04.png" alt="dental"> 
      <img class="img-thumbnail zoom" src="images/05.png" alt="dental"> 
      <img class="img-thumbnail zoom" src="images/06.png" alt="dental"> 
     </div> 
    </div> 
</div> 

當我試圖隱藏在div它的工作,所以我有錯誤的語法我覺得

+0

什麼? – ambarox

+0

'#image-zoom''不是'img'標籤,所以它不能擁有'src'屬性 – JFK

回答

50

更改src的圖像,而不是div:

$('#image-zoom img').attr("src",loc); 
3

變化線3引用圖像,而不是它的容器,包括:在控制檯

$('#image-zoom img').attr("src",loc); 
相關問題