0

我有这个无法更改的表结构:

<table class="sui-opt-in">
    <tbody>
        <tr>
            <th></th>
            <th><strong>Time</strong>
            </th>
            <th><strong>Cost</strong>
            </th>
        </tr>
        <tr style="display: none;" id="labor_summary_for_1">
            <td> <a href="#" onclick="jQuery('#labor_for_1').show(); jQuery('#labor_summary_for_1').hide(); return false;">
            <i class="icon-right  "></i>
           Name Here
          </a>

            </td>
            <td>1m</td>
            <td>£0.75</td>
        </tr>
    </tbody>
    <tbody id="labor_for_1" style="display: table-row-group;">
        <tr>
            <td> <a href="#" onclick="jQuery('#labor_summary_for_1').show(); jQuery('#labor_for_1').hide(); return false;">
              <i class="icon-down  "></i>
              Name Here
            </a>

            </td>
            <td></td>
            <td></td>
        </tr>
        <tr>
            <td></td>
            <td>1m</td>
            <td>£0.75 <a href="#" onclick="new Ajax.Request('/tickets/remove_time_spent/1247', {asynchronous:true, evalScripts:true, method:'delete', parameters:'work_id=456&amp;selected_view=my_tickets' + '&amp;authenticity_token=' + encodeURIComponent('7hd72GGlOMJINFvnvio5c6z0CTtRyxNUdU8uMJrKhps=')}); return false;"><i class="icon-remove  "></i></a>

            </td>
        </tr>
    </tbody>
    <tfoot>
        <tr>
            <td><strong>Total</strong>
            </td>
            <td><strong>1m</strong>
            </td>
            <td><strong>£0.75</strong>
            </td>
        </tr>
    </tfoot>
</table>

然后我有这个 jQuery 来删除最后一个表格单元格:

jQuery("#labor-section .sui-opt-in th:last-child, #labor-section .sui-opt-in  td:last-child").remove();

但不是我只想在最后一个单元格上保留 a href (删除价格)。

有什么建议么?

谢谢。

4

1 回答 1

2

尝试

jQuery('#labor-section .sui-opt-in').find('th:last-child, td:last-child').contents().filter(function(){
    return this.nodeType == 3
}).remove();

演示:小提琴

于 2013-10-02T12:08:22.293 回答