Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/83.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用jQuery删除单击的附加项_Jquery - Fatal编程技术网

使用jQuery删除单击的附加项

使用jQuery删除单击的附加项,jquery,Jquery,My+按钮复制元素,-按钮删除最后附加的元素 $('#btnNewMobilePhone').on('click', function(e){ e.preventDefault(); $('.phonemobile').append(' <div class="form-group"><label for="email" class="col-sm-3 control-label">Cep Telefonu</labe

My+按钮复制元素,-按钮删除最后附加的元素

$('#btnNewMobilePhone').on('click', function(e){
            e.preventDefault();
            $('.phonemobile').append(' <div class="form-group"><label for="email" class="col-sm-3 control-label">Cep Telefonu</label><div class="col-sm-4"><input type="text" class="form-control" name="phone_mobile[]"  placeholder="Mobile Phone"></div><div class="col-sm-2"> <a href="#"  class="btn btn-primary btnRemMobilePhone"> <i class="entypo-plus"> -</i> </a> </div></div>');
});
$('.phonemobile').on('click', '.btnRemMobilePhone', function(e){
            e.preventDefault();
            $('.phonemobile .form-group:last').remove();
});

要删除上次单击的元素,应使用:

$('.phonemobile.formgroup').find(e.currentTarget.remove()

e、 currentTarget将为您指定在表单组中单击的元素并将其删除。如果您只想删除已单击且位于表单组之外的元素,则应使用
$(e.currentTarget).remove()

您可以使用单击元素的上下文(
)遍历到最近的父级
表单组
元素,然后将其删除:

$('.phonemobile').on('click', '.btnRemMobilePhone', function(e){
   e.preventDefault();
   $(this).closest('.form-group').remove();
});
a在哪里?这看起来完全不清楚。
$('.phonemobile').on('click', '.btnRemMobilePhone', function(e){
   e.preventDefault();
   $(this).closest('.form-group').remove();
});