js中有多个输入...?

时间:2019-05-17 12:59:54

标签: javascript jquery html

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

$(document).on('click', "#modalgravar", function(){

var eURL = 'http://localhost:8081/datasnap/rest/TCadastros/Grupo/';
    var Ecdgrupo = $("#Cdgrupoedit").val();
    var Egrupo = $("#grupoedit").val();
    var eData ={"Cdgrupo": Ecdgrupo, "Grupos": Egrupo};

alert(JSON.stringify(eData));

    $.ajax({
       type:'PUT',
       url: eURL,
       data: JSON.stringify(eData),
        success: function(){
        alert("Editado!");
              },
        error: function(){
            alert("ERRO:  O grupo não foi editado!");
        }
    }); 

2 个答案:

答案 0 :(得分:1)

尝试一下

$(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>

答案 1 :(得分:0)

不确定我是否了解,但请告诉我

<script type='text/javascript'>
  $(function() {
    var button1 = $('#key1');
    var button2 = $('#key2');

    function keyUp(){
      console.log('1', button1.val());
      console.log('2', button2.val());

      var hasValue = ( button1.val() !== '' || button1.val() !== '');
      $('.enableOnInput').prop('disabled', hasValue);
    }

    button1.keyup(keyUp);
    button2.keyup(keyUp);
  });
</script>