除了第一行/最后一行/列之外的表格单元格的 JQuery 选择器
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/4027855/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
JQuery selector for table cells except first/last row/column
提问by MartinStettner
is there a way to directly select all 'inner' table cells (<td>
elements) of a table (i.e. all cells exceptthe ones in the first and last row and column) using a jquery selector expression?
有没有办法使用jquery选择器表达式直接选择表格的所有“内部”表格单元格(<td>
元素)(即除第一行和最后一行和列中的单元格之外的所有单元格)?
回答by Nick Craver
You can use :not()
with the :first-child
and :last-child
selectors, like this
您可以使用:not()
与:first-child
和:last-child
选择,这样
$('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)')
回答by saktiprasad swain
$('#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(table_name) .U 可以写 :last-child 跳过最后一个 td 来做一些任务。