首页 文章

表单元格的JQuery选择器,除了第一行/最后一行/列

提问于
浏览
23

有没有办法直接选择表的所有'inner'表格单元格( <td> 元素)(即所有单元格 except 在第一行和最后一行和列中的那些单元格)使用jquery选择器表达式?

2 回答

  • 56

    您可以将:not():first-child:last-child选择器一起使用,如下所示

    $('table td:not(:first-child, :last-child)')
    

    要排除第一行/最后一行:

    $('table tr:not(:first-child, :last-child) td:not(:first-child, :last-child)')
    
  • 0
    $('#table_name tr td:not(:first-child)').each(function () {
                        $(this).html('<input type="text" value="' + $(this).html() + '" />');
                    });
    

    这里的示例如何跳过表的第1个td(table_name).U可以写:last-child跳过最后一个td来执行某个任务 .

相关问题