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たが、間違った行が削除されます。さらに、チェックボックスで選択できる複数の行ではなく、1 つの行のみを選択しています。

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()

First parent() is the td Second is the tr

Here's a fiddle to demonstrate: http://jsfiddle.net/C2WMS/

于 2013-01-15T03:41:30.847 に答える