【发布时间】:2020-05-14 03:44:00
【问题描述】:
我有这个度数转换器的代码,它工作得很好。但我担心的一个问题是,当我选择一个度数时,比如摄氏温度,我输入我的数字并按下按钮,它会给我开尔文和华氏温度。但是假设我想在开尔文中有另一个温度,我在框中输入我的数字并按计算,它会生成华氏温度和摄氏温度,但它会将之前的开尔文值留在输入框中。我想要的是,根据您选择的温度,它会删除该文本。对于这个例子,我希望给 Kelvin 的数字消失。我试过 "document.getElementById("").style.display = "none"; 但所做的只是删除输入框。我只想让文本消失。有什么办法可以做到吗?
if(temperature == "Fahrenheit") {
calculate = Math.round((inputValue - 32) * 0.555);
document.getElementById("Celsius").value = calculate;
calculate = Math.round((inputValue - 32) * 0.555 + 273.15);
document.getElementById("Kelvin").value = calculate;
// hide fahrenheit value
}
else if(temperature == "Celsius") {
calculate = Math.round((inputValue * 0.555) + 32);
document.getElementById("Fahrenheit").value = calculate;
calculate = Math.round(inputValue + 273.15);
document.getElementById("Kelvin").value = calculate;
// hide celsius value
}
我希望你能明白我想问的问题,如果没有,我会尝试详细说明。
【问题讨论】:
标签: javascript html css