How to enable a disabled checkbox dynamically?

前端 未结 3 1248
遇见更好的自我
遇见更好的自我 2021-02-04 05:03

Please see here: http://jsfiddle.net/nShQs/

Press the disable button and then the enable button. The checkbox doesn\'t get enabled.

HTML:



        
3条回答
  •  不要未来只要你来
    2021-02-04 05:17

    Set the disabled property rather than the attribute (fiddle).

    function enable() {
        document.getElementById("check").disabled = false;    
    }
    
    function disable() {
        document.getElementById("check").disabled = true;
    }
    

    A control will remain disabled if the disabled attribute is present at all - regardless of its value (fiddle). Setting the disabled property to false will remove the disabled attribute.

提交回复
热议问题