在 html 中禁用提交输入

disable submit input in html

当我尝试此代码时,即使输入中有值,按钮输入仍保持禁用状态,为什么?

<form action ="/buy" method = "POST">
    <input id="symbol" type='text' name= 'symbol'/>
    <input id="shares" type= 'text' name = 'shares'/>
    <input id="submit" type= 'submit' disabled/>
</form>
<script>
    document.querySelector('#shares').onkeyup = function(){
        if (document.querySelector('#shares').value === '') {
            document.querSelector('#submit').disabled = true;
        } else {
           document.querSelector('#submit').disabled = false;  
        }
    }
</script>

else除了这条语句,其他都对,语法错误

<form action ="/buy" method = "POST">
    <input id="symbol" type='text' name= 'symbol'/>
    <input id="shares" type= 'text' name = 'shares'/>
    <input id="submit" type= 'submit' disabled/>
</form>
<script>
    document.querySelector('#shares').onkeyup = function(){
        if (document.querySelector('#shares').value === '') {
            document.querySelector('#submit').disabled = true;
        } else {
           document.querySelector('#submit').disabled = false;  
        }
    }
</script>

工作fiddle:https://jsfiddle.net/akcvtf2r/