Javascript 我需要暂停输入我的计算器显示器时,按钮是高亮。Can';我不明白我的setTimeout()为什么不工作。
在函数Javascript 我需要暂停输入我的计算器显示器时,按钮是高亮。Can';我不明白我的setTimeout()为什么不工作。,javascript,Javascript,在函数one中,您正在调用带有事件参数的AddDigit。在AddDigit中,对将返回NaN的对象使用parseInt。您可能希望将数字发送到AddDigit,因此更改函数one中的调用以发送适当的值。if语句必须读取if(event.className==“intro”)…而不是thing.className <html> <head> <title> Buttons</title> <style type="text/css"
one
中,您正在调用带有事件参数的AddDigit
。在AddDigit
中,对将返回NaN
的对象使用parseInt
。您可能希望将数字发送到AddDigi
t,因此更改函数one中的调用以发送适当的值。if语句必须读取if(event.className==“intro”)…而不是thing.className
<html>
<head>
<title> Buttons</title>
<style type="text/css">
.intro{background-color:;}
.duction{background-color:blue;}
</style>
</head>
<body>
<form name="calculator">
<input type="text" name="display" length="50" width="100">
<div>
<input type= "button" value="7" class="intro" id="seven" onclick="one(7)">
<input type= "button" value="8" class="intro" id="eight" onclick="one(8)">
<input type= "button" value="9" class="intro" id="nine" onclick="one(9)">
<input type= "button" value="+" class="intro" id="plus" onclick="one('+')">
<input type= "button" value="-" class="intro" id="minus" onclick="one('-')">
<div>
<input type= "button" value="4" class="intro" id="four" onclick="one(4)">
<input type= "button" value="5" class="intro" id="five" onclick="one(5)">
<input type= "button" value="6" class="intro" id="six" onclick="one(6)">
<input type= "button" value="x" class="intro" id="multiply" onclick="one('*')">
<input type= "button" value="/" class="intro" id="divide" onclick="one('/')">
<div>
<input type= "button" value="1" class="intro" id="one" onclick="one(1)">
<input type= "button" value="2" class="intro" id="two" onclick="one(2)">
<input type= "button" value="3" class="intro" id="three" onclick="one(3)">
<input type= "button" value="=" class="intro" id="equal" onclick="Evaluate()">
<div>
<input type= "button" value="0" class="intro" id="zero" onclick="one(0)">
<input type= "button" value="." class="intro" id="decimal" onclick="one('.')">
<input type= "button" value="c" class="intro" id="clear" onclick="clearDigit()">
</form>
<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;
var first;
var that;
var hilighted;
function one(event)
{
if (thing.className=="duction")
{alert("x");}
else {
clearTimeout(timer);
timer=setTimeout(function(){AddDigit(event);},200);};
}
function AddDigit(x)
{
if (typeof parseInt(x, 10) === "number" )
{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;
}
document.ondblclick=function(button)
{
clearTimeout(timer);
thing=button.target;
thing.value;
if(thing.className=="intro")
{thing.className="duction";}
else if(thing.className=="duction")
{thing.className="intro";}
}
function clearDigit()
{
document.calculator.display.value="";
}