1

我想计算 html 表中的唯一值。(RGB 颜色)

我正在使用第三方网站,它使用 PHP 在表中写入值。我无权访问 PHP 脚本。

PHP 在这里写“{colorcode}”一个我定义的 rgb-to-hex。我有 5 个十六进制值:
火:#FF8C00
医疗帮助:#FD0202
危险材料:#19070B
其他:#4876FF
技术援助:#0000FF

我的目标是,我可以单独计算每种颜色并将其写在另一个表中。
这是我的网站,其中显示了表格:https
://www.feuerwehr-forstern.de/einsaetze/ 我想计算的表格。

<table>
<tr style="font-size:16px; background-color:#670200; color:#FFFFFF;">
<th><b>Nr.</b></th>
<th><b>Missionstart</b></th>
<th><b>Title</b></th>
<th><b>Kind of mission</b></th>
<th><b>Place</b></th>
<th></th>
</tr>{liststart}
<tr>
<td style="color:#FFFFFF;" bgcolor={colorcode}><b>{missionnr}</b></td>
<td>{startdate} {starttime}</td>
<td>{missiontitle}</td>
<td>{kind of mission}</td>
<td>{missionplace}</td>
<td><u>{linkreport}</u></td>
</tr>{listend}
</table>

其他表,我想在“:”之后写下计数结果。

<table>
<tr style="font-size:16px; color:#FFFFFF;">
<th style="background-color:#FF8C00;"><b>fire:</b></th>
<th style="background-color:#FD0202;"><b>medical help:</b></th>
<th style="background-color:#19070B;"><b>hazardous materials:</b></th>
<th style="background-color:#4876FF;"><b>other:</b></th>
<th style="background-color:#0000FF;"><b>technical assistance:</b></th>
</tr>
</table>
4

3 回答 3

2

你可以试试这个:var blue_count = $('[bgcolor=#0000FF]').length获取属性值为的td元素的计数。然后你可以在任何你想要的地方附加计数值。bgcolor#0000FF

但这只是你解决它的想法......不是最好的方法......

祝你好运

于 2018-04-26T09:09:02.277 回答
0

我已经查看了您的代码和您在顶部问题中提供的链接,并且在链接中,颜色代码都是大写的,如下所示:bgcolor="#4876FF"
因此您无法使用这样的小写选择器获取它们: $('[bgcolor=#4876ff]').size()
您应该首先修复它. 然后,在每个页面中,您只需要检查一次 document.ready 事件。所以其中之一将完成工作:

$(function() {

});

只需在这些块之一中编写您的代码。
祝您好运...

于 2018-04-29T08:09:10.340 回答
0

这是新的代码。

<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script type="text/javascript">
$(function() {
var orange_count = $('[bgcolor=#ff8c00]').size()
$(".important1").text("Brand: " + orange_count);
});
</script>
<script type="text/javascript">
$(function() {
var red_count = $('[bgcolor=#fd0202]').size()
$(".important2").text("First Responder: " + red_count);
});
</script>
<script type="text/javascript">
$(function() {
var black_count = $('[bgcolor=#19070b]').size()
$(".important3").text("Gefahrstoffe: " + black_count);
});
</script>
<script type="text/javascript">
$(function() {
var royalblue_count = $('[bgcolor=#4876ff]').size()
$(".important4").text("Sonstige: " + royalblue_count);
});
</script>
<script type="text/javascript">
$(function() {
var blue_count = $('[bgcolor=#0000FF]').size()
$(".important5").text("Technische Hilfeleistung: " + blue_count);
});
</script>
<table>
<tr style="font-size: 16px; color: #ffffff;">
<th style="background-color: #ff8c00;"><b class="important1">Brand</b></th>
<th style="background-color: #fd0202;"><b class="important2">First Responder</b></th>
<th style="background-color: #19070b;"><b class="important3">Gefahrstoffe</b></th>
<th style="background-color: #4876ff;"><b class="important4">Sonstige</b></th>
<th style="background-color: #0000ff;"><b class="important5">Technische Hilfeleistung</b></th>
</tr>
</table>

于 2018-04-29T06:06:02.153 回答