jQuery删除HTML表格列

前端之家收集整理的这篇文章主要介绍了jQuery删除HTML表格列前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我有一个这样的HTML表:
<table border="1">
    <tbody>
        <tr>
            <td><a href="#" class="delete">DELETE ROW</a>COL 1</td>
            <td><a href="#" class="delete">DELETE COL</a>COL 2</td>
            <td><a href="#" class="delete">DELETE COL</a>COL 3</td>
            <td><a href="#" class="delete">DELETE COL</a>COL 4</td>
            <td><a href="#" class="delete">DELETE COL</a>COL 5</td>
            <td><a href="#" class="delete">DELETE COL</a>COL 6</td>
        </tr>
        <tr>
            <td>ROW 1</td>
            <td>ROW 1</td>
            <td>ROW 1</td>
            <td>ROW 1</td>
            <td>ROW 1</td>
            <td>ROW 1</td>
        </tr>
        <tr>
            <td>ROW 2</td>
            <td>ROW 2</td>
            <td>ROW 2</td>
            <td>ROW 2</td>
            <td>ROW 2</td>
            <td>ROW 2</td>
        </tr>
    </tbody>
</table>

当我点击类“删除”的链接时,我需要一个功能删除指定的列。你能帮我吗 ?

解决方法

几年后,可能是更新这个问题的答案的时候了。
// Listen for clicks on table originating from .delete element(s)
$("table").on("click",".delete",function ( event ) {
    // Get index of parent TD among its siblings (add one for nth-child)
    var ndx = $(this).parent().index() + 1;
    // Find all TD elements with the same index
    $("td",event.delegateTarget).remove(":nth-child(" + ndx + ")");
});
原文链接:https://www.f2er.com/jquery/183000.html

猜你在找的jQuery相关文章