jQuery 多个 class 和 nth-child

jQuery multiple class and nth-child

我有一个 table 有多个 class。

<tr>
<td class='one two'>One</td>
<td class='one three'>Another</td>
<td class='one example'>Yet another</td>
<td class='one two'>Yet another</td>
<td class='four'>Four</td>
</tr>
<tr>
<td class='one two'>One</td>
<td class='one three'>Another</td>
<td class='one example'>Yet another</td>
<td class='one two'>Yet another</td>
<td class='four'>Four</td>
</tr>
<tr>
<td class='one two'>One</td>
<td class='one three'>Another</td>
<td class='one example'>Yet another</td>
<td class='one two'>Yet another</td>
<td class='four'>Four</td>
</tr>

我想要的是从每个包含 td 的 tr 中设置 first 文本有 class 'one',如果另一个 [=添加了 26=]。

我试过 classic 示例,但它不起作用:

        var i=0;
   $(".one:nth-child(1)").each(function() {
    temp[i] = $(this).text;
    console.log("Result: "+temp[i]);
        i++;
     });

但这行不通。

您需要使用:

$("tr td.one:first-child").each(function(i) {
  temp[i] = $(this).text();
  console.log("Result: "+temp[i]);
});

Working Demo