2015-07-06 58 views
0

我正在開發一個應用程序,其中有人可以從圖庫中選擇多個圖像。我附加了一個按鈕,每個圖片調用onclick函數。我怎樣才能刪除按鈕onclick附加圖像?刪除與按鈕相關的圖像

<div id="images"> 
    <img src="www.xyz.com/qwert.jpg" class="hi"> 
    <input type="button" class="multiple"> 
    <img src="www.xyz.com/qwerty.jpg" class="hi"> 
    <input type="button" class="multiple"> 
    <img src="www.xyz.com/qwertww.jpg" class="hi"> 
    <input type="button" class="multiple"> 
</div> 

回答

2

您可以使用此代碼:

$(".multiple").click(function() { 
    $(this).prev("img").remove(); 
}); 

片段

$(function() { 
 
    $(".multiple").click(function() { 
 
    $(this).prev("img").remove(); 
 
    }); 
 
})
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script> 
 
<div id="images"> 
 
    <img src="www.xyz.com/qwert.jpg" class="hi"> 
 
    <input type="button" class="multiple"> 
 
    <img src="www.xyz.com/qwerty.jpg" class="hi"> 
 
    <input type="button" class="multiple"> 
 
    <img src="www.xyz.com/qwertww.jpg" class="hi"> 
 
    <input type="button" class="multiple"> 
 
</div>

+0

如何隱藏/圖像被刪除後,刪除按鈕? –

+0

目前正在刪除它。你究竟想做什麼@NehilMistry? –

+1

完成。圖像被刪除後,我要求刪除按鈕。 '$(this).remove;' –