<html>
<head>
<title>我的计算器</title>
<script language="javascript">
var point=true;
var result=0;
var op="";
var cle=true;
var fristNum =true;
var lastNum;
function count(num)
{
if((fristNum==true)&&(isNaN(num)==false))
{
document.counter.screenTxt.value="";
fristNum=false;
}
if((num==".")&&(point==true))
{
if(document.counter.screenTxt.value.length==0)
{
document.counter.screenTxt.value="0";
point=false;
}
else
{
document.counter.screenTxt.value=document.counter.screenTxt.value+num;
point=false;
}
lastNum=document.counter.screenTxt.value;
}
if(isNaN(num)==false)
{
if(document.counter.screenTxt.value.length==0)
document.counter.screenTxt.value=num;
else
document.counter.screenTxt.value=document.counter.screenTxt.value+num;
lastNum=document.counter.screenTxt.value;
}
if((isNaN(num)==true)&&(num!=".")&&(num!="C")&&(num!="x")&&(num!="s"))
{
point=true;
fristNum=true;
if(num!="=")
{
op=num;
if(cle==true)
{
if(lastNum!="")
result =eval(result+op+lastNum);
cle=false;
}
else
{
result = eval(result+op+lastNum);
}
document.counter.screenTxt.value=result;
}
else
{
if(lastNum!="")
document.counter.screenTxt.value=eval(result+op+lastNum);
result=document.counter.screenTxt.value;
lastNum="";
op="";
cle=true;
}
}
if(num=="x")
{
document.counter.screenTxt.value=-parseFloat(document.counter.screenTxt.value);
lastNum="";
result=document.counter.screenTxt.value;
}
if(num=="s")
{
document.counter.screenTxt.value=Math.sqrt(parseFloat(document.counter.screenTxt.value)); //document.counter.screenTxt.value=parseFloat(document.counter.screenTxt.value)*parseFloat(document.counter.screenTxt.value);
result=document.counter.screenTxt.value;
}
if(num=="C")
{
document.counter.screenTxt.value="";
point=true;
result=0;
op="";
cle=true;
fristNum =true;
lastNum = 0;
}
if(document.counter.screenTxt.value=="NaN")
document.counter.screenTxt.value="";
}
</script>
</head>
<body>
<table width="32%" border="2" align="center" cellpadding="2" bordercolor="#333333" cellspacing="0"><form name="counter" style="text-align:center" dir="rtl">
<tr>
<td height="60px" colspan="5" align="left" valign="top">
<label>
<div align="right">
<input name="screenTxt" type="text" style=" border-bottom-color:#003333; height:60px; border:ridge; font-size:40px; color:#000000; width:250px; " maxlength="15" readonly="true" />
</div>
</label> </td>
</tr>
<tr>
<td width="47" height="40"> <div align="center">
<input name="7" onClick="count('7')" type="button" style="width:40px;height:40px" value="7"/>
</div></td>
<td width="47" height="40"> <div align="center">
<input name="8" type="button" id="8" onClick="count('8')" style="width:40px;height:40px" value="8"/>
</div></td>
<td width="47" height="40"> <div align="center">
<input name="9" onClick="count('9')" type="button" style="width:40px;height:40px" value="9"/>
</div></td>
<td width="44" height="40"> <div align="center">
<input name="+" onClick="count('+')" type="button" id="+" style="width:40px;height:40px" value="+"/>
</div></td>
<td width="49"> <div align="center">
<input name="C" type="button" onClick="count('C')" id="C" style="width:40px;height:40px" value="C"/>
</div></td>
</tr>
<tr>
<td width="47" height="40"><div align="center">
<input name="4" onClick="count('4')" type="button" id="4" style="width:40px;height:40px" value="4"/>
</div></td>
<td width="47" height="40"><div align="center">
<input name="5" onClick="count('5')" type="button" id="5" style="width:40px;height:40px" value="5"/>
</div></td>
<td width="47" height="40"><div align="center">
<input name="6" onClick="count('6')" type="button" id="6" style="width:40px;height:40px" value="6"/>
</div></td>
<td width="44" height="40"><div align="center">
<input name="-" onClick="count('-')" type="button" id="-" style="width:40px;height:40px" value="-"/>
</div></td>
<td width="49" height="40"><div align="center">
<input name="*" type="button" onClick="count('*')" style="width:40px;height:40px" value="*"/>
</div></td>
</tr>
<tr>
<td width="47" height="40"><div align="center">
<input name="1" onClick="count('1')" type="button" value="1" style="width:40px;height:40px"/>
</div></td>
<td width="47" height="40"><div align="center">
<input name="2" onClick="count('2')" type="button" style="width:40px;height:40px" value="2"/>
</div></td>
<td width="47" height="40"><div align="center">
<input name="3" onClick="count('3')" type="button" style="width:40px;height:40px" value="3"/>
</div></td>
<td width="44" height="40"><div align="center">
<input name="/" onClick="count('/')" type="button" id="/" style="width:40px;height:40px" value="/"/>
</div></td>
<td width="49" height="40"><div align="center">
<input name="sqrt" onClick="count('s')" type="button" style="width:40px;height:40px" value="SQRT"/>
</div></td>
</tr>
<tr>
<td width="47" height="40"><div align="center">
<input name="0" onClick="count('0')" type="button" style="width:40px;height:40px" value="0"/>
</div></td>
<td width="47" height="40"><div align="center">
<input name="." onClick="count('.')" type="button" style="width:40px;height:40px" value="."/>
</div></td>
<td height="40"><div align="center">
<input name="-(X)" type="button" id="-(X)" style="width:40px;height:40px" onClick="count('x')" value="-(X)"/>
</div></td>
<td height="40" colspan="2"><div align="center">
<input name="=" type="button" onClick="count('=')" style="width:80px;height:40px;" value="="/>
</div></td>
</tr>
</form>
</table>
</body>
</html>