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

时间:2021-02-07 22:19:57

is there a way to directly select all 'inner' table cells (<td> elements) of a table (i.e. all cells except the ones in the first and last row and column) using a jquery selector expression?

是否有一种方法可以使用jquery选择器表达式直接选择表的所有“内”表单元格(元素)(即所有单元格,除了第一行和最后一行中的所有单元格)?

2 个解决方案

#1


55  

You can use :not() with the :first-child and :last-child selectors, like this

您可以使用:not()和:first-child和:last-child selatorselector,如下所示

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

To exclude first/last rows as well:

排除第一/最后一行:

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

#2


0  

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

Here example how to Skip 1st td of a table(table_name) .U can write :last-child to skip last td to do some task.

这里的示例是如何跳过表的第一个td(表名). u可以写:last-child to Skip last td to do some task。

#1


55  

You can use :not() with the :first-child and :last-child selectors, like this

您可以使用:not()和:first-child和:last-child selatorselector,如下所示

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

To exclude first/last rows as well:

排除第一/最后一行:

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

#2


0  

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

Here example how to Skip 1st td of a table(table_name) .U can write :last-child to skip last td to do some task.

这里的示例是如何跳过表的第一个td(表名). u可以写:last-child to Skip last td to do some task。