如果没有键入11个字符,请不要启用按钮

hig*_*ode 0 html jquery input button

这是我在jquery中的代码,我认为逻辑是可以的,但我仍然无法让它工作.

    $(document).ready(function(){
    $('#send').attr('disabled',true);
    $('#inputText').keyup(function(){
        if($(this).val().length == 11)
            $('#send').attr('disabled', false);            
        else
            $('#send').attr('disabled', true);
        })
     });
Run Code Online (Sandbox Code Playgroud)

这是html,输入框和按钮

<input type="text" id="inputText" placeholder="XXX-XXX-XXX" maxlength="11"/>
<input type="button" id="send" value="submit"></input>
Run Code Online (Sandbox Code Playgroud)

gur*_*dio 5

$('#send').attr('disabled', true);
$('#inputText').keyup(function() {
if ($(this).val().length == 11){
  $('#send').attr('disabled', false);
}else{
  $('#send').attr('disabled', true);
  }
});
Run Code Online (Sandbox Code Playgroud)
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<input type="text" id="inputText" placeholder="XXX-XXX-XXX" maxlength="11"/>
<input type="button" id="send" value="submit"></input>
Run Code Online (Sandbox Code Playgroud)

试试这个