<script type='text/javascript'>
var farhen;
var celesius;
var kelvin;
function FtoC() {
farhen = document.getElementById("F").value
var para = document.getElementById("R")
celesius = ((farhen - 32) / 1.8).toFixed(1);
para.innerHTML = farhen + " degress in farhenheit is " + celesius + " in centigrade" + "<br>";
}
function FtoK() {
farhen = document.getElementById("C").value
var para1 = document.getElementById("L")
kelvin = ((farhen - 32) / 1.8 + 273).toFixed(1);
para1.innerHTML = farhen + "degress in farhenheit is " + Kelvin + " in kelvins" + '<br>';
}
</script>
<h1>Farhenheit Convertor</h1>
<p>
Input degrees in Fahrenheit to convert to Celsius
<input type = "text" id = "F" />
<button type="button" Onclick="FtoC();">Click Me!</button>
</p>
<p id="R"></p>
<p>
Input degrees in Fahrenheit to convert to Kelvin
<input type = "text" id = "C" />
<button type="button" Onclick="FtoK();">Click Me!</button>
</p>
<p id="L"></p>
</body>
如何使第二个事件无效,有人可以告诉我为什么它可能无法正常工作以及如何解决它。我正在尝试制作一个简单的转换器。
答案 0 :(得分:3)
当您在Kelvin
函数中连接输出字符串时,不应将FtoK()
大写。它应该如下:
function FtoK() {
farhen = document.getElementById("C").value
var para1 = document.getElementById("L")
kelvin = ((farhen - 32) / 1.8 + 273).toFixed(1);
para1.innerHTML = farhen + "degress in farhenheit is " + kelvin + " in kelvins" + '<br>';
}