<html>
<head>
<meta charset="utf-8">
<title>菜鸟教程(runoob.com)</title>
</head>
<head>
<script>
function convert(degree){
if (degree=="C"){
F=document.getElementById("c").value * 9 / 5 + 32;
document.getElementById("f").value=Math.round(F);
}
else{
C=(document.getElementById("f").value -32) * 5 / 9;
document.getElementById("c").value=Math.round(C);
}
}
</script>
</head>
<body>
<p><b>在下面输入框中插入一个数值:</b></p>
<form>
<input id="c" name="c" onkeyup="convert('C')"> 摄氏度<br>
等于<br>
<input id="f" name="f" onkeyup="convert('F')"> 华氏度
</form>
<p>注意使用<b>Math.round()</b> 方法返回的结果是一个整数。</p>
</body>
</html>