[英]Remove label for dynamicaly created checkbox
I'm trying to delete both the checkbox and the label on success of json call. 我正在尝试在json调用成功时删除复选框和标签。 I have tried alsorts of code found here but so far have only managed to remove the checkbox.
我已经尝试过在这里找到代码的Alsorts,但到目前为止仅设法删除了该复选框。
Checkbox and label code 复选框和标签代码
<label class="checkbox"><input type="checkbox" id="<?php echo $row['name']; ?>" value="<?php echo $row['id']; ?>" name="delete[]" class="checkboxAdmin" /><?php echo $row['name']; ?> - <?php echo $row['email']; ?></label>
Jquery code jQuery代码
$(".delete_admin_but").click(function() {
$.post("includes/delete_admin.inc.php",{ checked_box : $('input:checkbox:checked').val()},function(json) {
if(json.result === "success") {
$("#deleteAdminError").html(json.message);
$("input:checkbox:checked").remove();
// $('.add_intern').get(0).reset();
}else{
$("#deleteAdminError").html(json.message);
}
});
});//submit click
The checkbox and label are dynamically created, and the only code I have found is for checkboxes and labels that are embeded in code with specific id that is easily identified, I hope that makes sense 该复选框和标签是动态创建的,我发现的唯一代码是针对嵌入到具有容易识别的特定ID的代码中的复选框和标签的,我希望这很有意义
If I understand well... 如果我了解...
Replace 更换
$("input:checkbox:checked").remove();
With 用
$("input:checkbox:checked").parent().remove();
Removing the parent (in your case that's the label) will remove the label and input altogether 删除父级(在您的情况下为标签)将删除标签并完全输入
Try selecting the checkbox parent an remove it: 尝试选择复选框父项并将其删除:
if(json.result === "success") {
$("#deleteAdminError").html(json.message);
$("input:checkbox:checked").parent('label').remove();
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.