有4个按钮
<button type="button" class="addf" idu="1">Plus</button>
<button type="button" class="unf" idu="1">Min</button>
<button type="button" class="addf" idu="2">Plus</button>
<button type="button" class="unf" idu="2">Min</button>
如何使用动态jQuery删除同一属性中的元素?例如,如果单击attr idu =“ 1”处的.addf按钮,则将删除attr idu =“ 1”处的.unf按钮。如果单击attr idu =“ 2”处的.addf按钮,则会删除attr idu =“ 2”处的.unf按钮
答案 0 :(得分:0)
无论如何..直到@David在他的评论中说..将idu=
更改为data-idu=
..因此您的代码应如下所示
$(document).ready(function(){
$('.addf').on('click' , function(){
var GetData = $(this).attr('data-idu');
$('.unf[data-idu="'+ GetData +'"]').remove();
});
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<button type="button" class="addf" data-idu="1">Plus</button>
<button type="button" class="unf" data-idu="1">Min</button>
<button type="button" class="addf" data-idu="2">Plus</button>
<button type="button" class="unf" data-idu="2">Min</button>