2017-02-19 67 views
-1

我在一次刪除一個圖像時遇到問題。當我雙擊時,所有圖像同時被刪除。我怎樣才能防止這種情況發生?這裏是我的腳本ondblclick所有圖像被刪除jquery

$(".bananas").on('dblclick', function(e) { 
    var whichtr = $(this).closest("div"); 
    whichtr.remove();  
}); 

$('img').on('click', function() { 
 
    $('#fotos').append('<div class="imgdrag"><img class="modal-content" src="' + $(this).attr('src') + '"/></div>'); 
 
    $('.imgdrag').draggable(); 
 
    $('#fotos').droppable(); 
 
    $('.modal-content').resizable(); 
 
    $(".download").attr("href", $(this).attr('src')); 
 
    $(".download").show(); 
 
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> 
 
<div id="fotos" class="bananas"> 
 
    <img class="modal-content" id="imgdisplay" src="http://lorempixel.com/output/technics-q-c-640-480-8.jpg"/> 
 
</div>

+1

添加整個代碼或至少html。 –

+0

您刪除容器。 (''dblclick',function(e){$(this).remove();});' – mplungjan

+0

請用[mcve]更新代碼。您至少還缺少一張圖片,向我們展示您的意思 - 使用您需要的代碼更新代碼片段 – mplungjan

回答

1

您登記在主容器中的雙擊事件。 如果你想刪除圖片,當他們雙擊,這應該是工作。

$(".bananas").on('dblclick', '.modal-content', function(e) { $(this).remove(); });