我想要一个文本框,旁边有一个按钮。当您单击按钮时,我想转换为华氏度或摄氏度并显示在另一个文本框中。我只完成华氏温度到摄氏温度,我可以在完成后复制代码。
<!DOCTYPE html>
<html>
<head>
<center>
<h1> Fahrenheit to Celsius Converter</h1>
<font size="+1" >
<p> Fahrenheit to Celsius</p>
<input type="text" name="ftc" id="ftc"/> <button type="button" onclick="fahrenheitCelsius()" /> Click to Convert </button>
<p>Celsius to Fahrenheit </p>
<input type="text" name="ctf" id="ctf" /> <button type="button" onclick="celsiusFahrenheit()" /> Click to Convert </button>
<p> Answer </p>
<input type="text" name="answer box" id="answer/>
<script>
function fahrenheitCelsius() {
var fsc = parseFloat(document.getElementById('ftc').value);
var cfc = (fsc-32) * (5/9);
document.getElementById('answer box').value = cfc;
return false;
document.writeIn(<input type="text" name="answer box" id="answer"/>)
}
</script>
</font>
</head>
</html>
答案 0 :(得分:1)
你犯了很多错误。以下是Fahrenheit to celcius的工作代码:https://jsfiddle.net/nm8ashr1/
<!DOCTYPE html>
<center>
<h1> Fahrenheit to Celsius Converter</h1>
<h2> Fahrenheit to Celsius</h2>
<input type="text" name="ftc" id="ftc"/> <button type="button" onclick="fahrenheitCelsius()"> Click to Convert</button>
<p>Celsius to Fahrenheit </p>
<input type="text" name="ctf" id="ctf" /> <button type="button" onclick="celsiusFahrenheit()"> Click to Convert</button>
<p> Answer </p>
<input type="text" name="answer box" id="answer"/>
<script>
function fahrenheitCelsius() {
var fsc = parseFloat(document.getElementById('ftc').value);
var cfc = (fsc-32) * (5/9);
document.getElementById('answer').value = cfc;
}
</script>