gpt4 book ai didi

Jquery - 在表中查找值

转载 作者:行者123 更新时间:2023-12-01 03:34:32 24 4
gpt4 key购买 nike

如何通过名称查找值?我找到名称“Obsah balení:”,我需要返回一个值3,18 m²或直接数字3,18

代码:

<table id="product-detail-info" class="pr-list-parametes">
<tbody>
<tr>
<td class="pr-detail-parameter-name">
Frézováná hrana:
</td>
<td class="pr-detail-parameter-value">
ne
</td>
</tr>
<tr>
<td class="pr-detail-parameter-name">
Obsah balení:
</td>
<td class="pr-detail-parameter-value">3,18 m²</td>
</tr>
<tr>
<td class="pr-detail-parameter-name">
Počet desek v balení:
</td>
<td class="pr-detail-parameter-value">7 ks</td>
</tr>
<tr>
<td class="pr-detail-parameter-name">
Počet m² na paletě:
</td>
<td class="pr-detail-parameter-value">127,2 m²</td>
</tr>
</tbody>
</table>

最佳答案

使用:cotains()伪类选择器和 next()方法。

console.log(
// select `td` which cotains the text
$('td:contains("Obsah balení:")')
// select the sibling `td` which immediately after the element
.next()
// get the text contents
.text()
)
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<table id="product-detail-info" class="pr-list-parametes">
<tbody>
<tr>
<td class="pr-detail-parameter-name">
Frézováná hrana:
</td>
<td class="pr-detail-parameter-value">
ne
</td>
</tr>
<tr>
<td class="pr-detail-parameter-name">
Obsah balení:
</td>
<td class="pr-detail-parameter-value">3,18 m²</td>
</tr>
<tr>
<td class="pr-detail-parameter-name">
Počet desek v balení:
</td>
<td class="pr-detail-parameter-value">7 ks</td>
</tr>
<tr>
<td class="pr-detail-parameter-name">
Počet m² na paletě:
</td>
<td class="pr-detail-parameter-value">127,2 m²</td>
</tr>
</tbody>
</table>

关于Jquery - 在表中查找值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38686791/

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