具有相同 类 的几个元素。但我只能得到第一个,为什么?

Several Elements with same Classes . but i can get only first one , why?

我有几个具有相同 class 名称的表, 这些表是通过循环从 php 代码创建的。 像这样

<?php 
$tableCount = 100;
$i=rand(1,999);
for ($i = 1; $i <= $tableCount; $i++) {
echo "<table class='tables'>";
echo "<tr class='myTr'>";
echo "<td  class='myTD'>";
echo $i;
echo "</td>";
echo "</tr>";
echo "</table>";
}

所以我们有 100 个不同内容的 tds, 我的问题在这里: 当循环在页面上创建时。当我想获取所有 Td 的 class 的所有 innerHtml 或 html() 时 编译器首先给我带来了 td 的 html() .

我的jquery代码:

var getclass = $(".myTD").html();

当我想更改内容或删除或其他内容时;我可以做这个。 例如 : 用相同的 class 更改所有 td 的所有内容:

 $(".myTD").html("changed contents");

但我想列出 .具有相同 class 的所有 td 的所有 html() 我的输出应该是这样的:

lists  outputs


  1,     14
  2,     188
  3,     20
  4,     2
  5,     99
  6,     11
  .,      .
  .,      .
  100,    73

然后结束。 但 。我的输入让我得到了第一个内容;

我该如何解决。请 :(

请注意,我想用 jquery 或 javascript 执行此操作。没有 php 或服务器端 .

使用.each()循环。

$(".myTD").each(function(i) {
    console.log(i, $(this).html());
});