gpt4 book ai didi

jquery - 根据单元格值为HTML/jquery表单元格设置颜色格式

转载 作者:太空宇宙 更新时间:2023-11-04 09:07:14 24 4
gpt4 key购买 nike

我有以下HTML,这些HTML使用jquery从csv文件中提取数据并将其显示在表中。我正在尝试对结果表进行一些条件格式化。我希望将任何值小于2.5的单元格设置为绿色背景。 2.5到3之间的值应为黄色。 3到100之间的任何值都应为红色。我已经尝试了网站上提供的许多不同解决方案,但到目前为止都没有奏效。

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatiable" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Inspection</title>
<link rel="stylesheet" href="mystyles.css" />
<meta http-equiv="refresh" content="120">


</head>
<body>

<script src="jquery.min.js"></script>
<script>
function opsi(data){
var allRows = data.split(/\r?\n|\r/);
var table = "<table id='scrapT'>";
for(var singleRow=0;singleRow<allRows.length;singleRow++){
if(singleRow === 0){
table += "<thead>";
table += "<tr>";
} else{
table += "<tr>";
}
var rowCells = allRows[singleRow].split(',');
for(var rowSingleCell=0;rowSingleCell<rowCells.length;rowSingleCell++){
if(singleRow === 0){
table += "<th>";
table += rowCells[rowSingleCell];
table += "</th>";
} else{
table += "<td>";
table += rowCells[rowSingleCell];
table += "</td>";
}
}
if(singleRow === 0){
table += "</tr>";
table += "</thead>";
table += "<tbody>";
} else{
table += "</tr>";
}
}
table += "</tbody";
table += "</table>";
$("body").append(table);
}

$.ajax({
url: "file.csv",
dataType: "text"
}).done(opsi);

</script>

最佳答案

这是一个很好的链接,其中包含可以引用的示例。

Changing background cell of table depending on value

关于jquery - 根据单元格值为HTML/jquery表单元格设置颜色格式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42378507/

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