javascript - js中的多个输入...?

标签 javascript jquery html

有效 - 当输入 #key1 为空时,我无法单击按钮。但我需要使用两个输入——#key1 和#key2。要做 - 当两者都为空或 1/2 时,没有人可以单击按钮。谢谢!!

<script type='text/javascript' src='http://code.jquery.com/jquery.min.js'></script>
<script type='text/javascript'>
  $(function() {
    $('#key1').keyup(function() {
      if ($(this).val() == '') {
        //Check to see if there is any text entered
        // If there is no text within the input ten disable the button
        $('.enableOnInput').prop('disabled', true);
      } else {
        //If there is text in the input, then enable the button
        $('.enableOnInput').prop('disabled', false);
      }
    });
  });
</script>

最佳答案

试试这个

$(function() {
  $("#key1, #key2").keyup(function() {
    if ($("#key1").val() == "" || $("#key2").val() == "") {
      $(".enableOnInput").prop("disabled", true);
    } else {
      $(".enableOnInput").prop("disabled", false);
    }
  });
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<input type="text" id="key1">
<input type="text" id="key2">
<button class="enableOnInput" disabled>Click me</button>

关于javascript - js中的多个输入...?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56186939/

相关文章:

javascript - 查找特定标签 a

javascript - 将鼠标悬停在提交/ anchor 上时如何检查是否已选中复选框并显示提示用户这样做的警报

javascript - node.js ParseError - 哪个文件抛出错误?

jquery - 首页上 "scroll to top"效果的元素

javascript - 如何在 JavaScript 中比较颜色?

javascript - HTML5 输入类型=日期 : Can I open/close the date picker with JavaScript?

javascript - jquery 中 window.resize() 和 window.on ('resize' ) 之间的区别

javascript - 如何使元素随着窗口大小的调整而增长(javascript)

javascript - 数据表列过滤器文本范围搜索

html - 无法将 Div 居中