def fnct_to_opt(t, k2, k1):
#EXPERIMENTAL CONSTANTS
v = 105
Co = 1500
A = (-np.log((k1/v)*Co))/k2
print("TRACE", "\nk2", k2, "\nt", t, "\nA", A, "\nother", k1, v, Co)
return ( (np.exp(-k2*(t+A))) - ((k1/v)*Co) )/ -k2
答案 0 :(得分:1)
使用由文本索引的对象来查找,其值是要设置的颜色:
const colorsByText = {
1: 'green',
2: 'yellow',
3: 'red'
};
function foo() {
$('#bar > table > tbody > tr').each(function () {
const text = $(this).find('td:nth-child(3)').text();
const color = colorsByText[text];
if (color) {
$(this).find('td:nth-child(1)').css('background-color', color);
}
});
}
如果文本始终是这 3 个属性之一,您可以删除 if
检查 - 或者,更好的是,使用数组而不是对象:
const colors = ['green', 'yellow', 'red'];
function foo() {
$('#bar > table > tbody > tr').each(function () {
const text = $(this).find('td:nth-child(3)').text();
const color = colors[text - 1];
$(this).find('td:nth-child(1)').css('background-color', color);
});
}