?? 計(jì)算器.htm
字號(hào):
?<html>
<head>
<title>計(jì)算器</title>
</head>
<script language="javascript">
<!--
var curoper;
var num1;
var curstate;
var preoper;
function setstartstate()
{
num1=0;
curstate="bestart";
curoper="start";
preoper="false";
}
function addnum(i)
{
if(preoper)
{
form1.text_total.value=i;
preoper=false;
}
else
{
if(form1.text_total.value=0)
{
form1.text_total.value=i;
curstate="beinteger";
}
else
form1.text_total.value+=i;
}
}
function addpoint()
{
if(curstate=="bestart"||curstate=="beinteger")
{
form1.text_total.value=".";
curstate="befloat";
}
}
function cleartext()
{
form1.text_total.value=0;
curstate="bestart";
curoper="start";
}
function count()
{
if(curoper="start")
{
switch(curoper)
{
case "+":
num1=parseFloat(num1)+parseFloat(form1.text_total.value);
break;
case "-":
num1=parseFloat(num1)-parseFloat(form1.text_total.value);
break;
case "*":
num1=parseFloat(num1)*parseFloat(form1.text_total.value);
break;
case "/":
num1=parseFloat(num1)/parseFloat(form1.text_total.value);
break;
}
form1.text_total.value=num1;
preoper=true;
}
curoper="start";
}
function setoper(oper)
{
preoper=true;
if(curoper=="start")
{
num1=parseFloat(form1.text_total.value);
curoper=oper;
}
else
{
count();
curoper=oper;
}
}
function usefunc(func)
{
switch(func)
{
case "sin":
form1.text_total.value=Math.sin(form1.text_total.value);
preoper=true;
break;
case "cos":
form1.text_total.value=Math.cos(form1.text_total.value);
preoper=true;
break;
case "tan":
form1.text_total.value=Math.tan(form1.text_total.value);
preoper=true;
break;
case "acos":
form1.text_total.value=Math.acos(form1.text_total.value);
preoper=true;
break;
case "asin":
form1.text_total.value=Math.asin(form1.text_total.value);
preoper=true;
break;
case "atan":
form1.text_total.value=Math.atan(form1.text_total.value);
preoper=true;
break;
case "exp":
form1.text_total.value=Math.exp(form1.text_total.value);
preoper=true;
break;
case "log":
form1.text_total.value=Math.log(form1.text_total.value);
preoper=true;
break;
case "1/x":
form1.text_total.value=1/form1.text_total.value;
preoper=true;
break;
case "sqrt":
form1.text_total.value=Math.sqrt(form1.text_total.value);
preoper=true;
break;
}
}
//-->
</script>
<body onload="setstartstate()"align="center">
<form name="form1">
<table border="2" align="center">
<tr>
<td colspan="12">
<font size="5">計(jì)算器</font>
</td>
</tr>
<tr align="center">
<td colspan="6">
<input type="text" name="text_total"size="40" value="0"/>
</td>
</tr>
<tr align="center">
<td>
<input type="button" value="sin" onclick="usefunc('sin')"/>
</td>
<td>
<input type="button" value="cos" onclick="usefunc('cos')"/>
</td>
<td>
<input type="button" value="1" onclick="addnum('1')"/>
</td>
<td>
<input type="button" value="2" onclick="addnum('2')"/>
</td>
<td>
<input type="button" value="3" onclick="addnum('3')"/>
</td>
<td>
<input type="button" value="+" onclick="setoper('+')"/>
</td>
</tr>
<tr align="center">
<td>
<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>
<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>
<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>
<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="javascript:form1.text_total.value=Math.PI"/>
</td>
<td>
<input type ="button" value="E" onclick="javascript:form1.text_total.value=Math.E"/>
</td>
<td colspan="2">
<input type="button" value="清除" onclick="cleartext()"/>
</td>
</tr>
</table>
</form>
</body>
</html>
?? 快捷鍵說(shuō)明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -