Javascript 输入上的引导启用按钮

Javascript 输入上的引导启用按钮,javascript,jquery,twitter-bootstrap,Javascript,Jquery,Twitter Bootstrap,我在正确完成这项工作时遇到了一些问题。 我希望我的“sendit”按钮在框中有任何字符时立即启用(删除禁用)。 我现在尝试了很多方法,但都没能成功。 HTML的一部分: <input type="password" id="inputPassword" class="form-control" placeholder="Password" required> <input id="sendit" class="btn btn-lg btn-primary btn-

我在正确完成这项工作时遇到了一些问题。 我希望我的“sendit”按钮在框中有任何字符时立即启用(删除禁用)。 我现在尝试了很多方法,但都没能成功。

HTML的一部分:

<input type="password" id="inputPassword" class="form-control" placeholder="Password" required>

    <input id="sendit" class="btn btn-lg btn-primary btn-block disabled" type="submit" value="Generate Codes"></input>

您的代码只在DOM就绪时检查字段一次

您需要将支票绑定到该字段上的键控事件:

$('my-field').keyUp(function() {
 if($(this).val() === '') {
  pass_error = 1;
} else {
  pass_error = 0;
  enableButton();
});

不要在
的HTML中使用
禁用的
类。
$('my-field').keyUp(function() {
 if($(this).val() === '') {
  pass_error = 1;
} else {
  pass_error = 0;
  enableButton();
});