我制作了一个带有图像的盒子,在右上角有一个X。当我单击它时,我希望它删除图像,框和X。但是什么也没发生。请不要苛刻,我是Jquery和javascript的新手。
<span class="removethis">
<div class="imformationbox1" >
<div class="col-lg-12">
<button type="button" class="deletebutton" id="" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">×< /span></button>
<a href="#" id="" title="Image 2"><img src="http://placehold.it/250x250 class="thumbnail img-responsive"></a>
</div>
</div>
</span>
<script>
$( ".deletebutton" ).click(function() {
$( ".removethis" ).remove();
});
</script>
Run Code Online (Sandbox Code Playgroud)
它非常简单..只需使用closest()
<script>
$(document).on('click',".deletebutton" ,function() {
$(this).closest(".removethis" ).remove();
});
</script>
Run Code Online (Sandbox Code Playgroud)
或者你可以使用parent()
<script>
$(document).on('click',".deletebutton" ,function() {
$(this).parent().parent().parent().remove();
});
</script>
Run Code Online (Sandbox Code Playgroud)
如果您动态附加此数据,只需使用
$(document).on('click',".deletebutton" , function(){});
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
728 次 |
| 最近记录: |