gpt4 book ai didi

jquery - 对 html 页面上表列的所有值求和

转载 作者:行者123 更新时间:2023-12-05 01:44:10 25 4
gpt4 key购买 nike

我有一个这样的示例表,每 5 分钟刷新一次数据以显示 latest.example -

TollFree                    US                      Canadian                      
7,312 826 141,128

我需要添加并计算以上所有内容的总数。

 Total Records -

这是我到目前为止尝试过的- http://jsfiddle.net/unKDk/2666/

HTML 页面有 6 个表,这些表具有不同的列数以进行相同的计算。尝试在所有 td 类中使用相同的脚本是相同的。

最佳答案

开始吧:

var summ = Number($("td:nth-child(1)").text()) + Number($("td:nth-child(2)").text()) + Number($("td:nth-child(3)").text());
console.log("Result: " + summ);
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<table>
<tr>
<th>A</th>
<th>B</th>
<th>V</th>
</tr>
<tr>
<td>1</td>
<td>2</td>
<td>3</td>
</tr>
</table>

根据您的要求进行编辑:

var summ = 0;
$("td").each(function() {
summ += Number($(this).text());
});;
console.log("Result: " + summ);
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<table>
<tr>
<th>A</th>
<th>B</th>
<th>V</th>
</tr>
<tr>
<td>1</td>
<td>2</td>
<td>3</td>
</tr>
</table>

关于jquery - 对 html 页面上表列的所有值求和,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47037889/

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