gpt4 book ai didi

javascript - 当 TD 不包含任何 ID 时如何使用 JavaScript 获取 TD 值

转载 作者:塔克拉玛干 更新时间:2023-11-02 22:44:06 26 4
gpt4 key购买 nike

我有一张表,其中 TD 没有 ID,但我有唯一的 TH 值。示例表是,

<table class="data-table" id="product-attribute-specs-table">
<colgroup>
<col width="25%">
<col>
</colgroup>
<tbody>
<tr class="first odd">
<th class="label">SKU</th>
<td class="data last">904532</td>
</tr>
<tr class="odd">
<th class="label">Width</th>
<td class="data last">20</td>
</tr>
<tr class="even">
<th class="label">Lead Time</th>
<td class="data last">49</td>
</tr>
<tr class="last odd">
<th class="label">Depth</th>
<td class="data last">63</td>
</tr>
</tbody>
</table>

我想在变量中读取提前期的值。我如何阅读是使用 javascript,即 var= ??

最佳答案

使用:contains()选择器过滤 TH 的内容并使用 .next() 选择下一个元素像这样:

var lt = $('th:contains("Lead Time")').next().text();

关于javascript - 当 TD 不包含任何 ID 时如何使用 JavaScript 获取 TD 值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33231693/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com