js实现简单四则运算计算器

<!DOCTYPE html> <html> <head lang="en"> <meta charset="UTF-8"> <title>js计算器</title> <script> function calculator(){ var num1 = parseFloat(document.getElementById("num1").value); var num2 = parseFloat(document.getElementById("num2").value); var result = parseFloat(document.getElementById("result").value); var mark = document.getElementById("mark").value; switch (mark){ case "+" : result = num1 + num2; break; case "-" : result = num1 - num2; break; case "*" : result = num1 * num2; break; case "http://www.likecs.com/" : result = num1 / num2; break; } document.getElementById("result").value = result; } </script> </head> <body> <input type="number" > <select> <option> + </option> <option> - </option> <option> * </option> <option> / </option> </select> <input type="number" > <button> = </button> <input type="text" > </body> </html>

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/zzjxdy.html