2016-09-28 109 views
0

用預覽創建圖片庫。當我點擊一張圖片時,它是空的div,但它不會追加新圖片。我錯過了什麼嗎?Jquery gallery empty/append

<div class="thumbnails"> 
    <img onmouseover="preview.src=classone.jpg" id="img1" class='pic' src="classone.jpg" alt="Image Not Loaded"/> 
    <img onmouseover="preview.src=danceshoes.jpg" id="img2" class='pic' src="danceshoes.jpg" alt="Image Not Loaded"/> 
    <img onmouseover="preview.src=lakemonroe.jpg" id="img3" class='pic' src="lakemonroe.jpg" alt="Image Not Loaded"/> 
    <img onmouseover="preview.src=danceshoes.jpg" id="img4" class='pic' src="danceshoes.jpg" alt="Image Not Loaded"/> 
    <img onmouseover="preview.src=danceshoes.jpg" id="img5" class='pic' src="danceshoes.jpg" alt="Image Not Loaded"/> 
    <img onmouseover="preview.src=dance.jpg" id="img6" class='pic' src="dance.jpg" alt="Image Not Loaded"/> 
    </div><br/> 

    <div class="preview" align="center"> 
    <img id="preview" src="classone.jpg" alt="N Image Loaded"/> 
    </div><br/> 


$(document).ready(function(){ 

    $('.pic').click(function(){ 
      $(".preview").remove(); 

     $(".preview").append(this); 
    }); 


}); 
+0

您不能追加的東西,你已經刪除 – adeneo

回答

0

您需要設置新的src而不是取消預覽圖像元素:

$('.pic').click(function(){ 
    $("#preview").attr("src",$(this).attr("src")); 
}); 
+0

完美。謝謝 –