2015-07-06 142 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;' –