JavaScript简单计算器

it2023-10-24  73

## JavaScript简单计算器 <!DOCTYPE html> <html lang="en" xmlns="http://www.w3.org/1999/html"> <head> <meta charset="UTF-8"> <title>简易计算器</title> </head> <br> <input type="text" id="num1" size="50"> <select id="select"> <option value="+">+</option> <option value="-">-</option> <option value="*">*</option> <option value="/">/</option> </select> <input type="text" id="num2" size="50"> <input type="button" value="计算" onclick="count()"></br> <input type="text" id="num3" size="50"> </body> <script> function count(){ var num1=document.getElementById("num1").value; var num2=document.getElementById("num2").value; var c=document.getElementById("select").value; num1=parseFloat(num1); num2=parseFloat(num2); switch (c) { case "+":document.getElementById("num3").value=parseInt(num1)+parseInt(num2); break; case "-":document.getElementById("num3").value=parseInt(num1)-parseInt(num2); break; case "*":document.getElementById("num3").value=parseInt(num1)*parseInt(num2); break; case "/":document.getElementById("num3").value=parseInt(num1)/parseInt(num2); break; } } </script> </html>

图解

最新回复(0)