3

有几篇关于此的帖子,但我似乎无法为我的案例找到合适的组合。我使用 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" />&nbsp;&nbsp;
                <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但这会删除错误的行。另外,它只选择一行,而不是可以用复选框选择的多行。

4

2 回答 2

13

尝试:

jQuery('input:checkbox:checked').parents("tr").remove();

演示:jsFiddle 示例

于 2013-01-15T03:42:54.777 回答
2

jQuery('#deleteform input[type="checkbox"]:checked').parent().parent().remove()

第一个parent()td 第二个是tr

这是一个要演示的小提琴:http: //jsfiddle.net/C2WMS/

于 2013-01-15T03:41:30.847 回答