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

它有效 - 当输入 #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>


守候你守候我
浏览 131回答 2
2回答

桃花长相依

不确定我是否理解但告诉我<script type='text/javascript'>&nbsp; $(function() {&nbsp; &nbsp; var button1 = $('#key1');&nbsp; &nbsp; var button2 = $('#key2');&nbsp; &nbsp; function keyUp(){&nbsp; &nbsp; &nbsp; console.log('1', button1.val());&nbsp; &nbsp; &nbsp; console.log('2', button2.val());&nbsp; &nbsp; &nbsp; var hasValue = ( button1.val() !== '' || button1.val() !== '');&nbsp; &nbsp; &nbsp; $('.enableOnInput').prop('disabled', hasValue);&nbsp; &nbsp; }&nbsp; &nbsp; button1.keyup(keyUp);&nbsp; &nbsp; button2.keyup(keyUp);&nbsp; });</script>
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

JavaScript