I'm a Javascript beginner and currently working on an effect! I hope that when there is a value in the input box, the button can be canceled and disabled so that the button can be clicked. When there is no value in the input box, the button will be disabled, but as long as the value is entered at the beginning, the button will be canceled and disabled. When the input box is When the value is empty, the button can still be clicked and the disabled attribute is not restored. I want to know which paragraph I wrote wrong?
In addition, how to make the button can also enter an empty string? At present, it seems that it is impossible to enter an empty string. The expectation is that entering an empty string will also allow the button to cancel the disabled attribute.
Thank you for watching my question, I hope I can get your help.
let inputDOM = document.querySelector('.input');
let BtnDOM = document.querySelector('.btn')
inputDOM.addEventListener('input', function() {
if (inputDOM.value >= 0) {
document.querySelector('.btn').removeAttribute("disabled")
} else {
document.querySelector('.btn').getAttribute("disabled")
}
});
<input type="number" class="input">
<button class="btn" disabled>Enter</button>