javascript - 如果输入了正确的信息,我怎样才能使按钮亮起?

标签 javascript html css button calculator

我做了一个排列组合计算器。如果排列 |选择组合并输入值后,计算按钮应亮起。如果不设置间隔,我怎么能做到这一点。我当前的代码:

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/

相关文章:

javascript - 使用 Javascript 添加订单项时如何处理 HTML 元素 ID 和 Javascript 引用?

javascript - 为什么我的 8 拼图解决方案在我创建两次数组时运行得更快

javascript - 使用javascript单击相应表行单选按钮时如何获取选择框值?

javascript - 克隆适用于一个元素,但不适用于整个 div

html - MooEditable : temporary disable editing

css - 将 xpath 转换为 css

javascript - 运算符(operator) "^"的目的是什么?

javascript - 无法使用 React js 进行内联编辑,因为收到警告 : Failed prop type

php - HTML Javascript 表单和 php 脚本 - 简单问题,求助!这段代码有什么作用?

javascript - 仅使用 CSS 自动调整此 div 的大小