Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/80.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 如果输入了正确的信息,如何使按钮亮起?_Javascript_Html_Css_Button_Calculator - Fatal编程技术网

Javascript 如果输入了正确的信息,如何使按钮亮起?

Javascript 如果输入了正确的信息,如何使按钮亮起?,javascript,html,css,button,calculator,Javascript,Html,Css,Button,Calculator,我做了一个排列组合计算器。如果选择排列组合,并输入值,则计算按钮应亮起。如何在不设置间隔的情况下执行此操作。我当前的代码: function checkCalc(){ if(((permutation==true)||(combination==true))&&(document.getElementById('r').value.length>0)&&(document.getElementById('n').value.length>0)){

我做了一个排列组合计算器。如果选择排列组合,并输入值,则计算按钮应亮起。如何在不设置间隔的情况下执行此操作。我当前的代码:

function checkCalc(){
 if(((permutation==true)||(combination==true))&&(document.getElementById('r').value.length>0)&&(document.getElementById('n').value.length>0)){
  calculate.style.backgroundColor="#ccccff";
  calculate.style.boxShadow="10px 10px 5px gray";
 }
 else{
  calculate.style.backgroundColor="gray";
 }
}

setInterval(checkCalc, 50);

如果我删除该函数(只留下If语句),它将不起作用。

在检查值时,您可以在
r
文本字段(我假设它是文本字段?)上设置事件侦听器,一旦您键入以下内容,它将被触发:

document.getElementById('r').onkeydown=function(){
 if(((permutation==true)||(combination==true))&&(document.getElementById('r').value.length>0)&&(document.getElementById('n').value.length>0)){
  calculate.style.backgroundColor="#ccccff";
  calculate.style.boxShadow="10px 10px 5px gray";
 }
 else{
  calculate.style.backgroundColor="gray";
 }
}

您需要在输入的keyup上调用此函数

我做了一个演示:

var置换=true;
var组合=真;
var calculate=document.getElementById('calculate')
函数checkCalc(){
if(((排列==true)| |(组合==true))&&&&(document.getElementById('r').value.length>0)&(document.getElementById('n').value.length>0)){
calculate.style.backgroundColor=“#ccccff”;
calculate.style.boxShadow=“10px 10px 5px灰色”;
}否则{
calculate.style.backgroundColor=“灰色”;
}
}

轻的