gpt4 book ai didi

html - 如何在 html5 的表格中突出显示/更改颜色到特定单词?

转载 作者:行者123 更新时间:2023-11-28 04:28:17 25 4
gpt4 key购买 nike

如果有一个表,最后一列称为结果。我想突出显示所有“失败”的单元格/文本。

我该怎么做?

我需要将 html5 与 kdb 中的表格一起使用。

目前我的邮件功能是这样的

htmlMailBody:{[emailadd;subject;message]
cmd:"echo \"",message, "\" | mutt -e \"my_hdr
From:abc@gmail.com\" -e \"my_hdr Content-Type:
text/html\" ",emailadd, " -s \"",subject,"\"";
sent:@[{system x;1b};cmd;{.log.error"Failure sending email. Reason: ",x;0b}];
if[sent; .log.info "Sent email to ",emailadd ];
};



mailRCP:bbc.gmail.com



htmlMailBody[mailRCP ;"health check";(,/)("<h2>SOD CHECKS<hr /></h2>";"<br />";markup[result];"<br />")];

这没有用。如果将 markup[result] 替换为 kdb 表,它将起作用。

最佳答案

要直接从 q 标记您的 HTML 表格,请使用 .h namespace 中的标记函数.

让你的表成为t

q)t
a b c d result
-------------------
94 66 8 82 success
8 24 62 47 failed
97 60 95 26 success
52 69 59 93 success

为 HTML td 元素制作一个相应的属性表 at。从空字典开始,没有属性。空字典是 ()!()

q)show at:flip (cols t)! (count each(cols t;t))#enlist ()!()
a b c d result
------------------------------
()!() ()!() ()!() ()!() ()!()
()!() ()!() ()!() ()!() ()!()
()!() ()!() ()!() ()!() ()!()
()!() ()!() ()!() ()!() ()!()

根据tresult列更新atresult列。

q)f:t[`result]=`failed
q)update result:([]color:(sum f)#enlist"red")from `at where f
q)at
a b c d result
----------------------------------------
()!() ()!() ()!() ()!() ()!()
()!() ()!() ()!() ()!() (,`color)!,"red"
()!() ()!() ()!() ()!() ()!()
()!() ()!() ()!() ()!() ()!()

我们可以使用.h.htac使用属性字典标记表格单元格。首先将表格单元格作为字符串:

q)string t cols t
"94" ,"8" "97" "52"
"66" "24" "60" "69"
,"8" "62" "95" "59"
"82" "47" "26" "93"
"success" "failed" "success" "success"

不要介意它们被翻转了。现在 at 中的字典也翻转了。

q)at cols t
()!() ()!() ()!() ()!()
()!() ()!() ()!() ()!()
()!() ()!() ()!() ()!()
()!() ()!() ()!() ()!()
()!() (,`color)!,"red" ()!() ()!()

我们可以将它们分别用作.h.htac 的第二个和第一个参数。 each-both adverb将遍历相应的行,但我们需要相应的单元格,因此 .h.htac'' 在行内的单元格内进行迭代。

q).h.htac''[`td;at cols t;string t cols t]
"<td>94</td>" "<td>8</td>" "<td>97</td>" "<td>52..
"<td>66</td>" "<td>24</td>" "<td>60</td>" "<td>69..
"<td>8</td>" "<td>62</td>" "<td>95</td>" "<td>59..
"<td>82</td>" "<td>47</td>" "<td>26</td>" "<td>93..
"<td>success</td>" "<td color=\"red\">failed</td>" "<td>success</td>" "<td>su..

函数 markup 组装 HTML table 元素:

markup:{[t]
th:.h.htc[`tr;]raze .h.htc[`th;] each string cols t; / table head
at:flip (cols t)! (count each(cols t;t))#enlist ()!(); / empty attribute dictionaries
f:t[`result]=`failed;
at:update result:([]color:(sum f)#enlist"red")from at where f; / attributes for result failed
tr:.h.htc[`tr;]each raze each flip .h.htac''[`td;at cols t;string t cols t]; / table rows
.h.htc[`table;] .h.htc[`thead;th],.h.htc[`tbody;raze tr]
}

使用属性字典表 是一种强大的技术,可适用于各种突出显示或为客户端脚本提供 ID。

关于html - 如何在 html5 的表格中突出显示/更改颜色到特定单词?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46777588/

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