gpt4 book ai didi

Jquery循环遍历表来查找特定的TD

转载 作者:行者123 更新时间:2023-12-01 08:08:14 26 4
gpt4 key购买 nike

我希望循环遍历表格并为每个负值的 TD 着色。现在它给整行着色,我可以改变什么来修复它?

http://jsfiddle.net/LEnRj/

Jquery
$('.my-table tr').each(function(index, tr) {
var lines = $('td', tr).map(function(index, td) {
return $(td).text();
});

if( lines[1] < 0 ) {
$(this).css('background-color', 'red');
}
});

最佳答案

伙计,这是 jQuery,少写多做:

$('.my-table td').filter(function() {
return parseFloat($.trim(this.innerHTML)) < 0;
}).css('background-color', 'red');

Fixed Fiddle

关于Jquery循环遍历表来查找特定的TD,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15257852/

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