[英]JavaScript - Colour a row on a table depending on a value of a cell
我需要那里的任何編碼人員的幫助。
當前,該代碼讀取哪個CSV文件,然后使用Powershell將其輸出到html文件。 而且我必須使用Powershell,因為此代碼還有其他位(此處未顯示)使用Powershell。
如何根據單元格的值在表上為行着色?
當前代碼如下。
$datagridView1.DataSource | Export-Csv c:\tmp\test.csv
#HTML OUTPUT
$head= @"
<style>
BODY{background-color:white;}
TABLE{border-width: 3px;border-style: solid; border-color:white;border-collapse:
collapse;}
TH{border-width: 3px;padding: 2px;border-style: solid;border-color: white;background- color:yellow}
</style>
<script type="text/javascript">
var allText =[];
var allTextLines = [];
var Lines = [];
var txtFile = new XMLHttpRequest();
txtFile.open("GET", "file://c:/tmp/test.csv", true);
txtFile.onreadystatechange = function()
{
allText = txtFile.responseText;
allTextLines = allText.split(/\r\n|\n/);
};
document.write(allTextLines);<br>
document.write(allText);<br>
document.write(txtFile);<br>
</script>
"@
$datagridView1.DataSource | convertto-html -head $head –body "<H2>Query</H2>" | Out-File C:\tmp\app.html
app.html文件似乎還在創建以下不在CSV文件中的四列(RowError,RowState,Table,ItemArray,HasErrors),我無法確定它的來源。
任何幫助將不勝感激
如果表數據的值為3,則以下內容將使任何表背景變為藍色:
$("td:contains('3')").css({'background-color':'blue'});
jQuery是簡化代碼的絕佳工具。 盡管JavaScript非常適合理解基本的編程原理以及面向對象的語法。 jQuery堅持寫更少,做更多的座右銘。
有關更多信息, 請訪問此站點 。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.