如何将文本输出到不是't输入不同颜色的文本

How do I output text to a table cell that isn't an input text with different colors?

本文关键字:文本 输入 颜色 输出      更新时间:2024-01-24

我正在用Javascript做一个简单的计算程序。我把这些脚本作为一个榜样:http://www.jsmadeeasy.com/javascripts/calculators/list_test.asp

我使用了Wind Chill Calc作为模型和示例。文本结果被放置在HTML样式的输入框中。我希望在表格的单元格中显示文本结果,而不是在输入文本框中。这是如何在Javascript中完成的?

第二部分是,我想用两种不同的颜色显示文本结果。红色表示负数,绿色表示零及以上。

第一个问题-而不是这个

form.windchill.value = chill;

做这个

document.getElementById("your_table_cell_id").innerHTML = chill;

第二个问题-将其添加到您的JS 中

var clr = ( chill <= 0 ) ? "red" : "green";
document.getElementById("your_table_cell_id").style.color = clr;