我是新手編程,並且正在製作一個簡單的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>
你攝氏度'input'有一個'name'屬性,但不是'id'財產。在HTML中用'id'替換'name'。在聲明變量時也請使用適當的變量聲明語法('var','let'或'const')。 – glhrmv
這裏有一個W3School教程:https://www.w3schools.com/js/tryit.asp?filename=tryjs_celsius –