简体   繁体   English

jQuery removeClass从按钮

[英]jQuery removeClass from button

I need to remove "disabled" class from button when there is at least one char in the input. 当输入中至少有一个字符时,我需要从按钮中删除“禁用”类。 This is jQuery code: 这是jQuery代码:

$('.reply').on('change', function() {
    if ($(this).val().length > 0) {
        $(".replyBtn").removeClass('disabled');
    }
});

This is HTML: 这是HTML:

<input type="text" name="reply" class="reply form-control" placeholder="Rašykite atsakymą...">
<br>
<button type="submit" class="replyBtn btn btn-success disabled">Atsakyti</button>

But it's not working and I don't get errors in console 但是它不起作用,控制台上也没有错误

 $('.reply').on('input', function() { if ($(this).val().length > 0) { $(".replyBtn").removeClass('disabled'); } else { $(".replyBtn").addClass('disabled'); } }); 
 .disabled { color: red } 
 <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <input type="text" name="reply" class="reply form-control" placeholder="Rašykite atsakymą..."> <br> <button type="submit" class="replyBtn btn btn-success disabled">Atsakyti</button> 

Use input 使用input

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM