How do I disable and re-enable a button in with javascript?

后端 未结 3 1892
野趣味
野趣味 2020-12-03 02:41

I can easily disable a javascript button, and it works properly. My issue is that when I try to re-enable that button, it does not re-enable. Here\'s what I\'m doing:

相关标签:
3条回答
  • 2020-12-03 03:10

    true and false are not meant to be strings in this context.

    You want the literal true and false Boolean values.

    startButton.disabled = true;
    
    startButton.disabled = false;
    

    The reason it sort of works (disables the element) is because a non empty string is truthy. So assigning 'false' to the disabled property has the same effect of setting it to true.

    0 讨论(0)
  • 2020-12-03 03:12

    you can try with

    document.getElementById('btn').disabled = !this.checked"

    <input type="submit" name="btn"  id="btn" value="submit" disabled/>
    
    <input type="checkbox"  onchange="document.getElementById('btn').disabled = !this.checked"/>

    0 讨论(0)
  • 2020-12-03 03:14
    <script>
    function checkusers()
    {
       var shouldEnable = document.getElementById('checkbox').value == 0;
       document.getElementById('add_button').disabled = shouldEnable;
    }
    </script>
    
    0 讨论(0)
提交回复
热议问题