【发布时间】:2011-04-30 23:34:28
【问题描述】:
有没有办法使用jquery 选择器表达式?
【问题讨论】:
有没有办法使用jquery 选择器表达式?
【问题讨论】:
您可以将: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)')
【讨论】:
table tr:not(:first-child, :last-child) td:not(:first-child, :last-child) 应该可以工作。
<th> 单元格也应该考虑。
<th> 只是在第一行/排除的行上,添加了行排除版本
<th> 的看法可能是正确的,尽管如果有多个表格部分,我可能倾向于将:first,:last 用于<tr>。可能不是这里的情况,但我想我还是会注意到它。 :o)
$('#table_name tr td:not(:first-child)').each(function () {
$(this).html('<input type="text" value="' + $(this).html() + '" />');
});
这里的例子是如何跳过表的第一个 td(table_name)。你可以写 :last-child 跳过最后一个 td 来做一些任务。
【讨论】: