检查行中的复选框后删除html表行

时间:2010-03-03 16:50:19

标签: jquery

如何在检查此行中的复选框后使用jquery html表行删除?

<table  id="mainTable">
    <tr>
        <th>
            name
        </th>
        <th>
            remove
        </th>
    </tr>
    <tr>
        <td>
            <input type="text" />
        </td>
        <td>
            <input type="checkbox" id="chb1" />
        </td>
    </tr>
    <tr>
        <td>
            <input type="text" />
        </td>
        <td>
            <input type="checkbox" id="chb2" />
        </td>
    </tr>
</table>

例如,我选择id为chb2的复选框,并希望删除第二行

2 个答案:

答案 0 :(得分:3)

对当前和未来的行尝试此操作:

$('input:checkbox').live('click',function() {        
  $(this).closest('tr').remove();
});

答案 1 :(得分:2)

试试这个:

$('input:checkbox').click(function() {        
    $(this).parent().parent().remove();
});