安科网
源代码:
点击运行
<!DOCTYPE html> <html> <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></p><b>Insert a number into one of the input fields below:</b></p> <form> <input id="c" name="c" onkeyup="convert('C')"> degrees Celsius<br> equals<br> <input id="f" name="f" onkeyup="convert('F')"> degrees Fahrenheit </form> <p>Note that the <b>Math.round()</b> method is used, so that the result will be returned as an integer.</p> </body> </html>
运行结果
Copyright © 2013 - 2019 Ancii.com All Rights Reserved
京ICP备18063983号-5
京公网安备11010802014868号