从行中删除一列

pri*_*dev 2 jquery jquery-selectors

这可能是一个基本问题......但我是jquery的新手.我需要从下面的表格行中删除最后一列

var ptr = $(this).closest("tr")

ptr.remove("td :last") 
Run Code Online (Sandbox Code Playgroud)

这是这样做的吗?

dkn*_*ack 11

  1. 如果要删除每行中的最后一个单元格(整列)

    您可以执行以下操作

    var ptr = $("#myTable").find("tr");
    ptr.find("td:last").remove();
    
    Run Code Online (Sandbox Code Playgroud)

    jsFiddle示范

  2. 如果您只想删除第一行中的最后一个单元格,请执行此操作

    var ptr = $("#myTable").find("tr:first");
    ptr.find("td:last").remove();
    
    Run Code Online (Sandbox Code Playgroud)

    jsFiddle示范

无论如何,我不知道你的桌子是如何结构的(你的问题没有来源).你应该使用theadtbody搜索引擎优化和良好的HTML.

<table id="myTable">
    <thead>
        <tr>
           <td>first column</td>
           <td>second column</td>
        </tr>
    </thead>

    <tbody>
         <tr>
           <td>first cell first row</td>
           <td>second cell first column</td>
        </tr>  
        <tr>
           <td>first cell second row</td>
           <td>second cell second column</td>
        </tr> 
    </tbody>        
</table>
Run Code Online (Sandbox Code Playgroud)