我做了一个排列组合计算器。如果排列 |选择组合并输入值后,计算按钮应亮起。如果不设置间隔,我怎么能做到这一点。我当前的代码:
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 语句),它就不起作用。
最佳答案
您需要在输入的 keyup 上调用此函数。
我做了一个demo:
var permutation=true;
var combination=true;
var calculate= document.getElementById('calculate')
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";
}
}
<input type ="text" id ='r' onkeyup="checkCalc()">
<input type ="text" id ='n' onkeyup="checkCalc()">
<button id="calculate">Light</button>
关于javascript - 如果输入了正确的信息,我怎样才能使按钮亮起?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37815438/