使用JavaScript写成的简易计算器,正常的操作下能正确的执行功能,但测试不全面,bug应该会有的,欢迎指出。这是页面部分代码。
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" ""> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> <title>JavaScript实现简单计算器</title> <script type="text/javascript" src="calculator.js"></script> <script type="text/javascript"> </script> <style type="text/css" media="all"> .myButton{ width: 80px; height: 30px; } </style> </head> <body> <table border="1" align="center"> <caption style="color: red">JS简易计算器--SAILOR20100312</caption> <tr><td><input type="text" id="showText" name="showText" size="50%" readonly="readonly"></td></tr> <tr> <td> <input class="myButton" type="button" value="7" onclick="handle(this.value)"> <input class="myButton" type="button" value="8" onclick="handle(this.value)"> <input class="myButton" type="button" value="9" onclick="handle(this.value)"> <input class="myButton" type="button" value="/" onclick="handle(this.value)"> <input class="myButton" type="button" value="清零" id="reset" onclick="handle(this.value)"> </td> </tr> <tr> <td> <input class="myButton" type="button" value="4" onclick="handle(this.value)"> <input class="myButton" type="button" value="5" onclick="handle(this.value)"> <input class="myButton" type="button" value="6" onclick="handle(this.value)"> <input class="myButton" type="button" value="*" onclick="handle(this.value)"> <input class="myButton" type="button" value="取消" id="reset" onclick="handle(this.value)"> </td> </tr> <tr> <td> <input class="myButton" type="button" value="1" onclick="handle(this.value)"> <input class="myButton" type="button" value="2" onclick="handle(this.value)"> <input class="myButton" type="button" value="3" onclick="handle(this.value)"> <input class="myButton" type="button" value="-" onclick="handle(this.value)"> <input class="myButton" type="button" value="sqrt" id="sqrt" onclick="handle(this.value)"> </td> </tr> <tr> <td> <input class="myButton" type="button" value="0" size="5" onclick="handle(this.value)"> <input class="myButton" type="button" value="备用" size="5" onclick=""> <input class="myButton" type="button" value="." size="5" onclick="handle(this.value)"> <input class="myButton" type="button" value="+" onclick="handle(this.value)"> <input class="myButton" type="button" value="等于" id="equel" onclick="handle(this.value)"> </td> </tr> </table> </body> </html>