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 に答える