来自tbody元素

<tbody id="results">
   <tr>
      <td><input type="checkbox"><a href="/../../Assets/Microsoft-Azure-roman_column.png">/../../Assets/Microsoft-Azure-roman_column.png</a></td>
      <td>Microsoft</td>
      <td>Azure</td>
      <td>roman_column.png</td>
   </tr>
   <tr>
      <td><input type="checkbox"><a href="/../../Assets/Microsoft-Azure-runphp.cmd">/../../Assets/Microsoft-Azure-runphp.cmd</a></td>
      <td>Microsoft</td>
      <td>Azure</td>
      <td>runphp.cmd</td>
   </tr>
   <tr>
      <td><input type="checkbox"><a href="/../../Assets/Microsoft-Azure-runphp.cmd">/../../Assets/Microsoft-Azure-runphp.cmd</a></td>
      <td>Microsoft</td>
      <td>Azure</td>
      <td>runphp.cmd</td>
   </tr>
   <tr>
      <td><input type="checkbox"><a href="/../../Assets/Microsoft-Azure-Picture1.png">/../../Assets/Microsoft-Azure-Picture1.png</a></td>
      <td>Microsoft</td>
      <td>Azure</td>
      <td>Picture1.png</td>
   </tr>
   <tr>
      <td><input type="checkbox"><a href="/../../Assets/Microsoft-Azure-vertical-align-scrnsht.png">/../../Assets/Microsoft-Azure-vertical-align-scrnsht.png</a></td>
      <td>Microsoft</td>
      <td>Azure</td>
      <td>vertical-align-scrnsht.png</td>
   </tr>
   <tr>
      <td><input type="checkbox"><a href="/../../Assets/Microsoft-Azure-vertical-align-scrnsht.png">/../../Assets/Microsoft-Azure-vertical-align-scrnsht.png</a></td>
      <td>Microsoft</td>
      <td>Azure</td>
      <td>vertical-align-scrnsht.png</td>
   </tr>
</tbody>

我的过程尝试获取href并将其粘贴在名为links的数组中:
        var resultRows = $('#results > tr > td > a');
        for (var thisAnchor in resultRows) links.push($(this).attr('href'));
        for (var thisLink in links) console.log(thisLink); // test

但是那个测试正在记录
0
1
.
.
.
171
172

到控制台而不是预期
/../../Assets/Microsoft-Azure-roman_column.png
/../../Assets/Microsoft-Azure-runphp.cmd
/../../Assets/Microsoft-Azure-runphp.cmd
/../../Assets/Microsoft-Azure-Picture1.png
/../../Assets/Microsoft-Azure-vertical-align-scrnsht.png
/../../Assets/Microsoft-Azure-vertical-align-scrnsht.png

为什么会这样,我该如何解决?

最佳答案

您可以只使用jQuery .each,如下所示:

$('tr').each(function() {
var href = $(this).find('a').attr('href');
links.push(href);
console.log(href);
});

09-25 16:44