<html>
<head>
<title> Buttons</title>
<style type="text/css">
.intro{background-color:;}
.duction{background-color:blue;}
.function{background-color:grey;}
.equals{background-color:orange;}
</style>
</head>
<body>
<form name="calculator">
<input type="text" name="display" length="50" width="100">
<div>
<input type= "button" value="7" class="intro" id="7" onclick="one(7)"></button>
<input type= "button" value="8" class="intro" id="8" onclick="one(8)"></button>
<input type= "button" value="9" class="intro" id="9" onclick="one(9)"></button>
<input type= "button" value="+" class="intro" id="+" onclick="Operate(+)"></button>
<input type= "button" value="-" class="intro" id="-" onclick="Operate(-)"></button>
<div>
<input type= "button" value="4" class="intro" id="4" onclick="one(4)"></button>
<input type= "button" value="5" class="intro" id="5" onclick="one(5)"></button>
<input type= "button" value="6" class="intro" id="6" onclick="one(6)"></button>
<input type= "button" value="x" class="intro" id="x" onclick="Operate(*)"></button>
<input type= "button" value="/" class="intro" id="/" onclick="Operate(/)"></button>
<div>
<input type= "button" value="1" class="intro" id="1" onclick="one(1)"></button>
<input type= "button" value="2" class="intro" id="2" onclick="one(2)"></button>
<input type= "button" value="3" class="intro" id="3" onclick="one(3)"></button>
<input type= "button" value="=" class="intro" id="=" onclick="Evaluate()"></button>
<div>
<input type= "button" value="0" class="intro" id="0" onclick="one(0)"></button>
<input type= "button" value="." class="intro" id="." onclick="one(.)"></button>
<input type= "button" value="c" class="intro" onclick="clearDigit()"></button>
<script type="text/javascript" src="C:\Users\LS\Desktop\QBJS\button.js">
</script>
</body>
</html>
var timer;
var object;
var thing;
var digit="";
var result;
function one(event)
{
clearTimeout(timer);
timer=setTimeout(function(){AddDigit(event);},200);
}
我的运算符按钮(+-/x)将运算符传递给“x”,当然我的数字按钮将数字传递给“x”。所以我想弄清楚如何在下面的 if 语句中检查数字和运算符,以便可以将参数传递给 document.calculator.display.value
function AddDigit(x)
{
if (x == ????)
{document.calculator.display.value=x;}
else
{document.calculator.display.value+=digit + x;}
}
function Evaluate()
{
result=eval(document.calculator.display.value);
document.calculator.display.value = result;
}
我还试图找出一种方法,在两个按钮被“突出显示”后交换两个按钮之间的文本,并将 className 更改为“duction”。(这个问题与第一个完全无关
document.ondblclick=function(button)
{
clearTimeout(timer);
thing=button.target;
if(thing.className=="intro")
{thing.className="duction";}
else if(thing.className=="duction")
{thing.className="intro";}
}
function clearDigit()
{
document.calculator.display.value="";
}