gpt4 book ai didi

jQuery - 比较两个数字并将背景属性添加到最大

转载 作者:行者123 更新时间:2023-11-28 03:35:58 25 4
gpt4 key购买 nike

我有几个表,每个表的最后一行包含以下数据:

<tr>
<td>59/128 (46%)</td>
<td>vs</td>
<td>45/90 (54%)</td>
</tr>

我想在背景上用黄色突出显示最大百分比数字。

这里的问题是如何忽略前几个数字,因为数字是动态出现的,所以我无法确定在我需要选择和比较的百分比数字之前有多少数字。

非常感谢您的宝贵时间。

最佳答案

下面的代码并不完全正确,但应该足以让您入门。我已经从表的最后一个 tr 中提取了值,您可以从那里小心。代码已正确记录,如果有任何问题,请告诉我。希望这会有所帮助:)

<script>
$( document ).ready(function() {
//Just some array to have the values available. You don't necessarily have to do this. This will just make the values available even after the loop ends.
var arr = new Array(3);
var i= 0;
//Add your table id here.
$('#yourtableid tr:last').each(function() {
$(this).find('td').each (function() {
//Iterating over each td in tr and then assigning value to each of the array element
arr[i] = $(this).html();
i++;
});
});
//Values as retrieved from the td
for(i = 0;i<3;i++){
console.log("Values in td: " +arr[i]);
}
});
</script>

关于jQuery - 比较两个数字并将背景属性添加到最大,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44481938/

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