在文本框中输入文本时,需要启用按钮。我究竟做错了什么?

码:

<body>
<script>
  function IsEmpty(){
    if(input1.value!=null){
      sendbutton.enabled==true;
    }
  }
  IsEmpty();
</script>

<input class="draft" name="input1" type="text"/>
     <button class="send" id="sendbutton" disabled>  Send </button>
     <ul class="messages">
     </ul>
</body>

最佳答案

将您的JavaScript更改为:

var input1 = document.getElementById('input1'),
    sendbutton = document.getElementById('sendbutton');
function IsEmpty(){
  if (input1.value){
    sendbutton.removeAttribute('disabled');
  } else {
    sendbutton.addAttribute('disabled', '');
  }
}

input1.onkeyup = IsEmpty;


和HTML:

<input class="draft" id="input1" type="text"/>
<button class="send" id="sendbutton" disabled>Send</button>


DEMO

09-17 17:07