简体   繁体   English

JavaScript-根据单元格的值在表格上为行着色

[英]JavaScript - Colour a row on a table depending on a value of a cell

I need a bit of help from any of the coders out there..... 我需要那里的任何编码人员的帮助。

Currently, the code Reads which a CSV file and then outputs it to a html file using Powershell. 当前,该代码读取哪个CSV文件,然后使用Powershell将其输出到html文件。 And I have to use Powershell as there are other bits to this code(not shown here) which uses Powershell. 而且我必须使用Powershell,因为此代码还有其他位(此处未显示)使用Powershell。

How do you colour a row on a table depending on a value of a cell? 如何根据单元格的值在表上为行着色?

Current bit of code look as below. 当前代码如下。


$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

The app.html file also seems to be creating the following four columns which are not in the CSV file (RowError, RowState, Table, ItemArray, HasErrors) and I can't figure out where its coming from. app.html文件似乎还在创建以下不在CSV文件中的四列(RowError,RowState,Table,ItemArray,HasErrors),我无法确定它的来源。

Any help would be greatly appreciated 任何帮助将不胜感激

The following would make any table background a color of blue if the table data has a value of 3: 如果表数据的值为3,则以下内容将使任何表背景变为蓝色:

$("td:contains('3')").css({'background-color':'blue'});

jQuery is an amazing tool for simplifying your code. jQuery是简化代码的绝佳工具。 Though JavaScript is great for understanding basic programing principles along with object oriented syntax. 尽管JavaScript非常适合理解基本的编程原理以及面向对象的语法。 jQuery sticks to its motto of write less, do more. jQuery坚持写更少,做更多的座右铭。

For more information visit this site . 有关更多信息, 请访问此站点

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM