<html><head><title>计算器 var curState;var curOper;var num1;var preOper;function setStartState(){curState="beStart";num1=0;curOper="start";preOper=false;}function addNum(i){if(preOper){ cal.total.value=i; preOper=false;}else{ if(cal.total.value=="0") { cal.total.value=i; curState="beInteger"; } else cal.total.value+=i;}}function addPoint(){if(curState=="beStart" || curState=="beInteger"){ cal.total.value+="."; curState="beFloat";}}function cleartext(){cal.total.value="0";curState="beStart";curOper="start";}function count(){if(curOper!="start"){ switch(curOper) { case "+": num1=parseFloat(num1) + parseFloat(cal.total.value); break; case "-": num1=parseFloat(num1) - parseFloat(cal.total.value); break; case "*": num1=parseFloat(num1) * parseFloat(cal.total.value); break; case "/": num1=parseFloat(num1) / parseFloat(cal.total.value); break; } cal.total.value=num1; preOper=true;}curOper="start";}function setOper(oper){preOper=true;if(curOper="start"){ /*num1=parseFloat(cal.total.value);*/ num1=0+cal.total.value; curOper=oper;}else{ count(); curOper=oper;}}function useFunc(func){switch(func){case "sin":cal.total.value=Math.sin(cal.total.value);preOper=true;break;case "cos":cal.total.value=Math.cos(cal.total.value);preOper=true;break;case "asin":cal.total.value=Math.asin(cal.total.value);preOper=true;break;case "acos":cal.total.value=Math.acos(cal.total.value);preOper=true;break;case "tan":cal.total.value=Math.tan(cal.total.value);preOper=true;break;case "atan":cal.toatl.value=Math.atan(cal.total.value);preOper=true;break;case "log":cal.total.value=Math.log(cal.total.vlaue);preOper=true;break;case "exp":cal.total.value=Math.exp(cal.total.value);preOper=true;break;case "sqrt":cal.total.value=Math.sqrt(cal.total.value);preOper=true;break;case "1/x":cal.total.value=1/cal.total.value;preOper=true;break;}}</script><body onLoad="setStartState()"><div align="center"><font color="#c0c0c0" size="7"><strong>计算器</strong></font></div><form name="cal"><font size="6" color="#002063" ><table width="300" align="center" bordercolor="#00ff00" style="height: 213px" ><tr align="center"><td height="48" colspan="6"> <input name="total" type="text" value="0" style="width: 317px; height: 24px"></td></tr><tr align="center"><td width="72" height="44"><input type="button" value="sin" onClick="useFunc('sin')" style="width: 40px; height: 23px" size="18"></td><td style="width: 52px"><input type="button" value="cos" onClick="useFunc('cos')" style="width: 40px; height: 23px" size="18"></td><td width="72"><input type="button" value="1" onClick="addNum('1')" style="width: 50px; height: 32px; color: mediumblue; font-family: 华文新魏;"></td><td width="72"><input type="button" value="2" onClick="addNum('2')" style="width: 50px; height: 32px; color: mediumblue; font-family: 华文新魏;"></td><td width="72"><input type="button" value="3" onClick="addNum('3')" style="width: 50px; height: 32px; color: mediumblue; font-family: 华文新魏;"></td><td width="72"><input type="button" value="+" onClick="setOper('+')" style="width: 50px; height: 32px; color: mediumblue; font-family: 华文新魏;"></td></tr><tr align="center"><td height="30"><input type="button" value="asin" onClick="useFunc('asin')" style="width: 40px; height: 23px" size="18"></td><td style="width: 52px"><input type="button" value="acos" onClick="useFunc('acos')" style="width: 40px; height: 23px" size="18"></td><td><input type="button" value="4" onClick="addNum('4')" style="width: 50px; height: 32px; color: mediumblue; font-family: 华文新魏;"></td><td><input type="button" value="5" onClick="addNum('5')" style="width: 50px; height: 32px; color: mediumblue; font-family: 华文新魏;"></td><td><input type="button" value="6" onClick="addNum('6')" style="width: 50px; height: 32px; color: mediumblue; font-family: 华文新魏;"></td><td><input type="button" value="-" onClick="setOper('-')" style="width: 50px; height: 32px; color: mediumblue; font-family: 华文新魏;"></td></tr><tr align="center"><td height="30"><input type="button" value="tan" onClick="useFunc('tan')" style="width: 40px; height: 23px" size="18"></td><td style="width: 52px"><input type="button" value="atan" onClick="useFunc('atan')" style="width: 40px; height: 23px" size="18"></td><td><input type="button" value="7" onClick="addNum('7')" style="width: 50px; height: 32px; color: mediumblue; font-family: 华文新魏;"></td><td><input type="button" value="8" onClick="addNum('8')" style="width: 50px; height: 31px; color: #6666ff; font-family: 华文新魏;"></td><td><input type="button" value="9" onClick="addNum('9')" style="width: 50px; height: 32px; color: mediumblue; font-family: 华文新魏;"></td><td><input type="button" value="*" onClick="setOper('*')" style="width: 50px; height: 32px; color: mediumblue; font-family: 华文新魏;"></td></tr><tr align="center"><td height="30"><input type="button" value="log" onClick="useFunc('log')" style="width: 40px; height: 23px" size="18"></td><td style="width: 52px"><input type="button" value="exp" onClick="useFunc('exp')" style="width: 40px; height: 23px" size="18"></td><td><input type="button" value="0" onClick="addNum('0')" style="width: 50px; height: 32px; color: mediumblue; font-family: 华文新魏;"></td><td><input type="button" value="." onClick="addPoint()" style="width: 50px; height: 32px; color: mediumblue; font-family: 华文新魏;"></td><td><input type="button" value="=" onClick="count()" style="width: 50px; height: 32px; color: mediumblue; font-family: 华文新魏;"></td><td><input type="button" value="/" onClick="setOper('/')" style="width: 50px; height: 32px; color: mediumblue; font-family: 华文新魏;"></td></tr><tr align="center" ><td height="30"><input type="button" value="sqrt" onClick="useFunc('sqrt')" style="width: 40px; height: 23px" size="18"></td><td style="width: 52px"><input type="button" value="1/x" onClick="useFunc('1/x')" style="width: 40px; height: 23px" size="18"></td><td><input type="button" value="pi" onClick="cal.total.value=Math.PI" style="width: 40px; height: 23px"></td><td><input type="button" value="E" onClick="cal.total.value=Math.E" style="width: 40px; height: 23px"></td><td colspan="2"><input type="button" value="清除" onClick="cleartext()" style="width: 40px; height: 23px"></td></tr></table></font><p align="center"><font size="7"><a href="http://656707738.qzone.qq.com/"style=text-decoration:none><font color="#FF0000" face="华文新魏">进入我的 QQ 空间</font></a></font> </p><p align="center"><font color="#CCFF00" size="6" face="华文行楷"><a href="http://656707738.qzone.qq.com/"style=text-decoration:none><font face="宋体">QQ;656707738</font></a></font></p></form></body></html>