<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>-----计算器!-----</title>
<script type="text/javascript">
<!--
var data=new Array(); //记忆参与每步运算的数据
var sign=new Array(); //记忆参与每步运算的运算符
var result=new Array(); //记忆每步的结果
var str="";
var step=0;
var sp=-1;
var yinyueIsPlay=true; //控制背景音乐的播放
function anniu(i){ //感应前台按钮的数据
switch(i){
case '+': ;
case '-': ;
case '*': ;
case '/': ;
case '%': ;
case '√': ;
case '=': checkReSign(i);break;
case '.': ;
case 0: ;
case 1: ;
case 2: ;
case 3: ;
case 4: ;
case 5: ;
case 6: ;
case 7: ;
case 8: ;
case 9: jieShou(i); break;
case '←': xiaoQu(i);break;
case '±': jieShou('-');break;
case 'ON': ;window.location.href="jisuanqi.html";break;
case "OFF": window.close();
case 'M+': jiyiPlus(); break;
case 'M-': jiyiMinus(); break; //记忆结果的上下翻转
case '∮': if(yinyueIsPlay)
document.getElementById("shengyin").play();
else
document.getElementById("shengyin").stop();
yinyueIsPlay=!yinyueIsPlay;
break;
}
}
function checkReSign(i){ //检查是否是连续重复按下运算符号
data[step]=parseFloat(str);
if(step==0) {
if(str!="") compute(i);
}
else
switch(sign[step-1]){
case '√':
case '=':
if(result[step-1].toString()!="")
compute(i);
break;
default :
if(str!="") compute(i);
}
}
function compute(ch){ //计算的主体方法
if(step==0)
result[0]=parseFloat(str);
else
switch(sign[step-1]){
case '+':
result[step]=result[step-1]+data[step]; break;
case '-':
result[step]=result[step-1]-data[step]; break;
case '*':
result[step]=result[step-1]*data[step]; break;
case '/':
result[step]=result[step-1]/data[step]; break;
case '%':
result[step]=result[step-1]/data[step]*100; break;
case '√':
result[step]=Math.sqrt(result[step-1]);break;
case '=':
step--;
}
sign[step]=ch;
document.form1.resultText.value=result[step].toString();
document.form1.dataText.value="";
str="";
step++;
showSign(ch);
sp=-1;
}
function jieShou(i){ //接受从前台传入的字符,将其连接成字符串
if(str.length<=12){
str=str+i;
showData();
}
else {
document.form1.dataText.value="";
setTimeout('showData()',300);
}
}
function xiaoQu(ch){ //输入数据 退后
showSign(ch);
if(str.length>0){
str=str.substr(0,str.length-1);
showData();
}
}
function showSign(ch){ //显示运算操作符
document.form1.operatorText.value=ch;
}
function showData(){ //同步显示从按钮捕获到字符而连接成的字符串
document.form1.dataText.value=str;
}
function jiyiMinus(){
if(sp==-1) {
sp=result.length-1;
}
document.form1.dataText.value=result[sp].toString();
str=result[sp].toString();
sp--;
}
function jiyiPlus(){
sp++;
if(sp==result.length) sp=0;
document.form1.dataText.value=result[sp].toString();
str=result[sp].toString();
}
//-->
</script>
</head>
<body>
<embed src="siledouyaoai.mp3" width="0" height="0" hidden="true" autostart="false" loop="true" id="shengyin" name="shengyin">
<form name="form1" method="post" action="">
<table width="211" border="0" align="center" cellpadding="0" cellspacing="0">
<tr>
<td height="35" colspan="3" align="center" valign="bottom"><img src="jisuanqi1.jpg" width="211" height="35"></td>
</tr>
<tr>
<td width="24" rowspan="2" align="center"><img src="jisuanqi2.jpg" width="24" height="46"></td>
<td width="162" height="16" align="right" valign="bottom" bgcolor="#BFBEC3"><input name="resultText" type="text" id="resultText" size="20" maxlength="20" readonly="true"></td>
<td width="25" rowspan="2" align="center"><img src="jisuanqi4.jpg" width="25" height="46" ></td>
</tr>
<tr>
<td width="162" height="16" align="right" valign="bottom" bgcolor="#BFBEC3"><input name="operatorText" type="text" id="operatorText" size="2" maxlength="2" readonly="true" ><input name="dataText" type="text" id="dataText" size="17" maxlength="17" readonly="true"></td>
</tr>
<tr>
<td colspan="3" align="center"><img src="jisuanqi5.jpg" width="211" height="201" usemap="#Map" border="0">
<map name="Map">
<area shape="circle" coords="106,139,12" href="#3" onClick="anniu(3)">
<area shape="circle" coords="34,170,12" href="#0" onClick="anniu(0)">
<area shape="circle" coords="104,80,13" href="#9" onClick="anniu(9)">
<area shape="circle" coords="35,81,12" href="#7" onClick="anniu(7)">
<area shape="circle" coords="71,139,12" href="#2" onClick="anniu(2)">
<area shape="circle" coords="71,110,12" href="#5" onClick="anniu(5)">
<area shape="circle" coords="71,170,12" href="#." onClick="anniu('.')">
<area shape="circle" coords="71,81,12" href="#8" onClick="anniu(8)">
<area shape="circle" coords="104,167,13" href="#+/-" onClick="anniu('±')">
<area shape="circle" coords="34,110,13" href="#4" onClick="anniu(4)">
<area shape="circle" coords="106,44,12" href="#music" onClick="anniu('∮')">
<area shape="circle" coords="176,40,12" href="#SQRT" onClick="anniu('√')">
<area shape="circle" coords="31,40,12" href="#ON" onClick="anniu('ON')">
<area shape="circle" coords="177,138,12" href="#M+" onClick="anniu('M+')">
<area shape="circle" coords="150,50,12" href="#%" onClick="anniu('%')">
<area shape="circle" coords="104,109,13" href="#6" onClick="anniu(6)">
<area shape="circle" coords="35,141,12" href="#1" onClick="anniu(1)">
<area shape="circle" coords="176,109,12" href="#M-" onClick="anniu('M-')">
<area shape="circle" coords="139,109,12" href="#*" onClick="anniu('*')">
<area shape="circle" coords="140,79,12" href="#/" onClick="anniu('/')">
<area shape="circle" coords="140,139,12" href="#-" onClick="anniu('-')">
<area shape="circle" coords="61,50,12" href="#OFF" onClick="anniu('OFF')">
<area shape="circle" coords="175,79,12" href="#MRC" onClick="anniu('←')">
<area shape="circle" coords="105,139,12" href="#3" onClick="3" onClick="anniu(3)">
<area shape="circle" coords="139,167,12" href="#+" onClick="anniu('+')">
<area shape="circle" coords="177,167,12" href="#=" onClick="anniu('=')">
</map></td>
</tr>
</table>
</form>
</body>
</html>