网页计算器 效果 代码 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182<!DOCTYPE html><html> <head> <meta charset="utf-8" /> <title>计算器</title> <style type="text/css"> #calc{ border: solid 1px black; width: 300px; height: 300px; text-align: center; background-color: gainsboro; } input[type=text]{ border: solid 1px black; width: 150px; height: 40px; margin: 10px; } input[type=button]{ width: 40px; height: 40px; margin: 5px; font-size: 30px; } </style> <script type="text/javascript"> function cal(btn){ var num=btn.value; switch (num) { case "=": document.getElementById("input").value = eval(document.getElementById("input").value); break; case "C": document.getElementById("input").value = ""; break; default: document.getElementById("input").value = document.getElementById("input").value + num; break; } } </script> </head> <body> <div id="calc"> <input type="text" id="input" value="" /><br /> <input type="button" value="7" onclick="cal(this)"/> <input type="button" value="8" onclick="cal(this)"/> <input type="button" value="9" onclick="cal(this)"/> <input type="button" value="×" onclick="cal(this)"/> <br /> <input type="button" value="4" onclick="cal(this)"/> <input type="button" value="5" onclick="cal(this)"/> <input type="button" value="6" onclick="cal(this)"/> <input type="button" value="-" onclick="cal(this)"/> <br /> <input type="button" value="1" onclick="cal(this)"/> <input type="button" value="2" onclick="cal(this)"/> <input type="button" value="3" onclick="cal(this)"/> <input type="button" value="+" onclick="cal(this)"/> <br /> <input type="button" value="c" onclick="cal(this)"/> <input type="button" value="0" onclick="cal(this)"/> <input type="button" value="/" onclick="cal(this)"/> <input type="button" value="=" onclick="cal(this)" /> </div> </body></html>