有几个帖子,但我似乎无法为我的案例找到合适的组合。我使用jquery提交了一个包含AJAX的表单:
<form id="deleteform" name="myform" action="">
<table id="webcam-table">
<thead>
<tr>
<th>Name</th>
<th>...</th>
<th><input type="checkbox" name="checkboxselectall" title="Select All" />
<button type="submit" class="deletebutton" name="delete_video" title="Delete the selected videos">Delete</button></th>
</tr>
</thead>
<tbody>
<tr >
<td>some data</td>
...
<td><input type="checkbox" value="<?php echo $this->result_videos[$i]["video_name"]; ?>" title="Mark this video for deletion"/></td>
</tr>
</tbody>
</table>
</form>
我需要选择已选中复选框的表格行并将其删除。
var checked = jQuery('input:checkbox:checked').map(function () {
return this.value;
}).get();
var $this = jQuery(this);
jQuery.ajax({
type: 'POST',
url: 'index.php?option=com_recordings&task=deletevideos&format=raw',
data: {checkedarray:checked},
success: function(data){
jQuery('#deleteform input:checkbox').each(function(){
if(this.checked){
$this.parents("tr").remove();
}
});
}
});
我已经尝试parents
,如上所述closest
但是删除了错误的行。此外,它只选择一行而不是可以使用复选框选择的多行。
答案 0 :(得分:10)
答案 1 :(得分:2)
jQuery('#deleteform input[type="checkbox"]:checked').parent().parent().remove()
首先parent()
是td
第二个是tr
这是一个演示的小提琴:http://jsfiddle.net/C2WMS/