我是编程新手,正在制作一个简单的JavaScript应用程序,该应用程序可以转换输入的摄氏度值并输出华氏温度。它似乎不起作用,我在做什么错。
function CelciusToFarenheit() {
a = document.getElementById("Celcius").value;
b = document.getElementById("Farenheit");
f = (a * (9/5) + 32);
b.innerHTML = f;
}
<html>
<head>
<title>Projects</title>
<script src="pr.js" type="text/js"></script>
<link href="main.css" rel="stylesheet" type="text/css" />
</head>
<body>
<div class="div1">
Convert celcius to farenheit:
<br>
<br>
Celcius: <input type="number" name="Celcius" id="Celcius"><br>
Farenheit: <span id="Farenheit"></span><br>
<button id="submit" onclick="CelciusToFarenheit()">Calculate</button>
</div>
</body>
</html>
最佳答案
您想更改名称或在输入中添加id=Celcius
function CelciusToFarenheit() {
a = document.getElementById("Celcius").value;
b = document.getElementById("Farenheit");
f = (a * (9 / 5) + 32);
b.innerHTML = f;
}
<html>
<head>
<title>Projects</title>
<script src="pr.js" type="text/js"></script>
<link href="main.css" rel="stylesheet" type="text/css" />
</head>
<body>
<div class="div1">
Convert celcius to farenheit:
<br>
<br> Celcius: <input type="number" id="Celcius"><br> Farenheit: <span id="Farenheit"></span><br>
<button id="submit" onclick="CelciusToFarenheit()">Calculate</button>
</div>
</body>
</html>