简体   繁体   English

当按钮高亮显示时,我需要暂停输入到计算器显示屏。 无法弄清楚为什么我的setTimeout()无法正常工作。

[英]I need suspend input to my calculator display when buttons are hi-lighted. Can't figure out why my setTimeout() isnt working.

<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;

This function is supposed to suspend input to the calc. 该函数应该暂停对calc的输入。 display when a button is highlighted. 高亮显示按钮时显示。 When no button is hi-lighted, it adds digits to the display. 当没有按钮高亮显示时,它将在显示屏上添加数字。 My timer was working before I added the if statement, and I can't figure out what needs to change to accommodate the if statement. 在添加if语句之前,我的计时器已经开始工作,无法确定需要更改哪些内容以容纳if语句。

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="";
}

In function one you are calling AddDigit with a parameter which is an event. 在函数one您正在使用事件参数调用AddDigit In AddDigit you use parseInt on that object which will return NaN . AddDigit ,在该对象上使用parseInt ,该对象将返回NaN Probably what you want is to send the digit to AddDigi t so change your call in function one to send that appropriate value. 您可能想要的是将数字发送到AddDigi t,因此在函数one更改您的调用以发送该适当的值。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM