0

祝大家好日子,

这真的不是问题。但我只想知道是否有另一种方法可以找到特定元素的值。所以我这里有一个样本。

<table class="test">
  <thead>..</thead>
  <tfoot>..</tfoot>
  <tbody>
    <tr>
      <td class="foo>1<td>
      <td class="foo>7<td>
      <td class="foo>1<td>
    </tr>
  </tbody>
</table>

<table class="test">
  <thead>..</thead>
  <tfoot>..</tfoot>
  <tbody>
    <tr>
      <td class="foo>1<td>
      <td class="foo>3<td>
      <td class="foo>2<td>
    </tr>
  </tbody>
</table>

<table class="test">
  <thead>..</thead>
  <tfoot>..</tfoot>
  <tbody>
    <tr>
      <td class="foo>5<td>
      <td class="foo>1<td>
      <td class="foo>3<td>
    </tr>
  </tbody>
</table>

我的解决方案:

$("table.test").each(function() {
  alert($(this).find("td.foo:first").text());
});

所以这将提醒每个表的所有第<td class="foo">一个。

我想知道是否有另一种方法可以做到这一点。

谢谢

4

1 回答 1

1

您可以使用.find()

$("table.test").find("td.foo:first").each(function() {
  alert($(this).text());
});

演示:小提琴

于 2013-10-29T02:14:31.647 回答