Add disabled attribute to input element using Javascript

后端 未结 7 604
执念已碎
执念已碎 2021-01-30 00:44

I have an input box and I want it to be disabled and at the same time hide it to avoid problems when porting my form.

So far I have the following code to hide my input:<

7条回答
  •  伪装坚强ぢ
    2021-01-30 01:10

    If you're using jQuery then there are a few different ways to set the disabled attribute.

    var $element = $(...);
        $element.prop('disabled', true);
        $element.attr('disabled', true); 
    
        // The following do not require jQuery
        $element.get(0).disabled = true;
        $element.get(0).setAttribute('disabled', true);
        $element[0].disabled = true;
        $element[0].setAttribute('disabled', true);
    

提交回复
热议问题