Enable/disable a button in pure javascript

后端 未结 4 765
傲寒
傲寒 2020-12-06 00:34

I want to enable/disable a button without jquery. Here\'s my code:

btn.setAttribute(\"disabled\", true);

Works. But this doesn\'t -- a butt

4条回答
  •  隐瞒了意图╮
    2020-12-06 01:07

    function getElement(elm){
        return document.getElementById(elm);
    }
    
    /*-------------FUNCTION TO DISABLE AN TEXT BOX------------------*/
    function disable(elm){
        return getElement(elm).setAttribute("disabled", true);
    }
    //==============================================================//
    /*--------------FUNCTION TO ENABLE AN TEXT BOX------------------*/
    function enable(elm){
        return getElement(elm).removeAttribute("disabled");
    }
    //==============================================================//
    
    function disableEnable(){
          if(getElement("button").disabled){
                enable("button");
                enable("input-button");
          }
          else{
                disable("button");
                disable("input-button");
          } 
    }
    
    
    
    


提交回复
热议问题