HTML - 由值确定的字体颜色

时间:2022-08-22 08:53:50

How can one set a font color to be determined by the value of the text enclosed using HTML and/or CSS. The enclosed text is constrained to integer values. The desired effect is similar to a heat map.

如何设置字体颜色由使用HTML和/或CSS括起的文本的值确定。随附的文本约束为整数值。期望的效果类似于热图。

A possible solution might look like this:

可能的解决方案可能如下所示:

<FONT COLOR=function> 1 </FONT>
<FONT COLOR=function> 100 </FONT>

where "function" would resolve to:

“功能”将解决的地方:

<FONT COLOR="red"> 1 </FONT>
<FONT COLOR="green"> 100 </FONT>

1 个解决方案

#1


3  

Using jQuery something like the following may suit your needs (based on what I think it is you tried to explain):

使用类似下面的jQuery可能适合您的需求(基于我认为您试图解释的内容):

$('font').each(function() {
    var value = $(this).text();
    var colorVal;
    // determine your color
    $(this).attr('color', colorVal);
});

But I would recommend using classes or style manipulation as the HTML you are proposing to use has been deprecated.

但我建议使用类或样式操作,因为您建议使用的HTML已被弃用。

#1


3  

Using jQuery something like the following may suit your needs (based on what I think it is you tried to explain):

使用类似下面的jQuery可能适合您的需求(基于我认为您试图解释的内容):

$('font').each(function() {
    var value = $(this).text();
    var colorVal;
    // determine your color
    $(this).attr('color', colorVal);
});

But I would recommend using classes or style manipulation as the HTML you are proposing to use has been deprecated.

但我建议使用类或样式操作,因为您建议使用的HTML已被弃用。