第n个子选择器不起作用

时间:2014-10-30 11:31:17

标签: jquery jquery-selectors

第n个子选择器无效。我的代码段如下,

$(this).parent().parent().("tr :nth-child(" + colNo + ")" ).text(value);

这里,colNo和value是一个变量。 提前谢谢。

2 个答案:

答案 0 :(得分:1)

您可以使用

$(this).closest("tr").find("td").eq(colNo).text(value);

答案 1 :(得分:0)

您正在选择表格的colNo行,然后更改它的文本,这可能不是您想要的。 您可能想要更改行内单元格的文本,或者使用以下替代方法实际选择一列单元格:

   $(this).parent().parent().("tr:nth-child(" + colNo + ") td" ).text(value);
   $(this).parent().parent().("tr td:nth-child(" + colNo + ")" ).text(value);
相关问题