首先获取所有的值<;td>;在一张桌子里<;tr>;除了第一个使用Javascript

首先获取所有的值<;td>;在一张桌子里<;tr>;除了第一个使用Javascript,javascript,Javascript,我需要从表中的每个tr(第一个tr除外)返回第一个td的值的逗号分隔列表 在下面的html表格示例中,我需要返回: 4153641537 <table class="product-options"> <tbody> <tr class="top-row"> <td>NEW Code</td> <td>OLD Code</td> <td>Other Code</td> </tr>

我需要从表中的每个tr(第一个tr除外)返回第一个td的值的逗号分隔列表

在下面的html表格示例中,我需要返回:

4153641537

<table class="product-options">
<tbody>
<tr class="top-row">
<td>NEW Code</td>
<td>OLD Code</td>
<td>Other Code</td>
</tr>
<tr>
<td>41536</td>
<td>40227</td>
<td>60544</td>
</tr>
<tr>
<td>41537</td>
<td>41097</td>
<td>58974</td>
</tr>
</tbody>
</table>

新代码
旧代码
其他代码
41536
40227
60544
41537
41097
58974

document.queryselectoral('table.product-options>tbody>tr:not(:first child)>td:first child')

querySelectorAll
返回一个
NodeList

tr:not(:first child)
返回除第一行以外的所有行

td:first child
返回第一个单元格

我建议你仔细阅读

有了
document.querySelectorAll
和正确的查询,就很容易了:

在这种情况下,我们使用
:not
来不选择我们不想要的
tr
:第一个孩子
。对于我们想要的第一个td

table.product-options tr:not(.top-row) > td:first-child
const list=document.queryselectoral(“table.product-options tr:not(.top row)>td:first child”);
控制台日志(列表)

新代码
旧代码
其他代码
41536
40227
60544
41537
41097
58974

对,情况如何?如果需要,请重新阅读。您现在应该知道,这不是一个为您编写代码的网站,但您仍然给我们这样一个“我有,我想,我到目前为止什么都没做”的问题“…我正在尝试这个,但它不起作用:function(){var element=document.querySelectorAll('table.product-options>tr:not(.top row)>td:first child');var id=element.innerText;return id;}它返回一个
NodeList
(某种
数组
):其中有几个元素!您应该console.log()来查看它是什么样子的:)对不起,我不明白。我对javascript一无所知。
function () {
  let node = 'table.product-options tr:not(.top-row) td:first- 
child'
  let Sku = document.querySelectorAll(node);

  return Array.prototype.map.call(Sku, function(node) {
    return node.textContent.replace(/\s/g, '');
  });
}