<HTML>
<head>
<META NAME="GENERATOR" CONTENT="javascript Editor 2">
<TITLE>计算器</TITLE>
<script language="javascript">
<!--
var Iscomputed=false;
var buttonDown=false;
var operation=0;
function pushStack(form)
{
form.stack.value=form.display.value;
form.display.value=0;
Iscomputed=false;
}
function reset(form)
{
form.stack.value=0;
form.display.value=0;
Iscomputed=false;
operation=0;
buttonDown=false;
}
function addChar(input,character)
{
if(Iscomputed==true)
pushStack(input.form);
if(input.value==null||input.value=="0")
input.value=character;
else
input.value+=character;
Iscomputed=false;
buttonDown=false;
}
function deleteChar(input)
{
input.value=input.value.substring(0,input.value.length-1);
}
function goOperation(form)
{
output=parseFloat(form.display.value);
var value1=parseFloat(form.stack.value);
var value2=parseFloat(form.display.value);
form.output1.value=value1;
form.output2.value=value2;
if(operation==1)
{
form.display.value=value1+value2;
}
else if(operation==2)
{
form.display.value=value1-value2;
}
else if(operation==3)
{
form.display.value=value1*value2;
}
else if(operation==4)
{
if(form.display.value==0)
{
form.display.value="ERROR";
form.stack.value=0;
operation=0;
}
else
{
form.display.value=value1/value2;
}
}
if(buttonDown==false)
form.stack.value=output;
Iscomputed=true;
buttonDown=true;
}
function add(form)
{
goOperation(form);
operation=1;
}
function subtract(form)
{
网页计算器制作源代码
最新推荐文章于 2022-01-15 13:54:40 发布
![](https://img-home.csdnimg.cn/images/20240711042549.png)