|
<HTML>
<head><title></title></head>
<script language="javascript">
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>
<style type="text/css">
table{
border:solid 1px #b9cdf6;
border-collapse:collapse;
}
td{
border:1px;
height:25px;
color:silver;
}
</style>
<body onLoad="setStartState()">
<form name="cal">
<table width="474" height="316" border="2" align="center" bordercolor="#b9cdf6" bgcolor="#e5e1d4">
<tr align="center">
<td height="48" colspan="6">
<input name="total" type="text" value="0" size="40"></td>
</tr>
<tr align="center">
<td width="72" height="44">
<input type="button" value="sin" onClick="useFunc('sin')"></td>
<td width="72">
<input type="button" value="cos" onClick="useFunc('cos')"></td>
<td width="72">
<input type="button" value="1" onClick="addNum('1')"></td>
<td width="72">
<input type="button" value="2" onClick="addNum('2')"></td>
<td width="72">
<input type="button" value="3" onClick="addNum('3')"></td>
<td width="72">
<input type="button" value="+" onClick="setOper('+')"></td>
</tr>
<tr align="center">
<td height="48">
<input type="button" value="asin" onClick="useFunc('asin')"></td>
<td>
<input type="button" value="acos" onClick="useFunc('acos')"></td>
<td>
<input type="button" value="4" onClick="addNum('4')"></td>
<td>
<input type="button" value="5" onClick="addNum('5')"></td>
<td>
<input type="button" value="6" onClick="addNum('6')"></td>
<td>
<input type="button" value="-" onClick="setOper('-')"></td>
</tr>
<tr align="center">
<td height="53">
<input type="button" value="tan" onClick="useFunc('tan')"></td>
<td>
<input type="button" value="atan" onClick="useFunc('atan')"></td>
<td>
<input type="button" value="7" onClick="addNum('7')"></td>
<td>
<input type="button" value="8" onClick="addNum('8')"></td>
<td>
<input type="button" value="9" onClick="addNum('9')"></td>
<td>
<input type="button" value="*" onClick="setOper('*')"></td>
</tr>
<tr align="center">
<td height="59">
<input type="button" value="log" onClick="useFunc('log')"></td>
<td>
<input type="button" value="exp" onClick="useFunc('exp')"></td>
<td>
<input type="button" value="0" onClick="addNum('0')"></td>
<td>
<input type="button" value="." onClick="addPoint()"></td>
<td>
<input type="button" value="=" onClick="count()"></td>
<td>
<input type="button" value="/" onClick="setOper('/')"></td>
</tr>
<tr align="center" >
<td height="46">
<input type="button" value="sqrt" onClick="useFunc('sqrt')"></td>
<td>
<input type="button" value="1/x" onClick="useFunc('1/x')"></td>
<td>
<input type="button" value="pi" onClick="cal.total.value=Math.PI"></td>
<td>
<input type="button" value="E" onClick="cal.total.value=Math.E"></td>
<td colspan="2">
<input type="button" value="清零" onClick="cleartext()"></td></tr>
</table>
</form>
</body>
</html> |
|