Add disabled attribute to input element using Javascript

后端 未结 7 753
执念已碎
执念已碎 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 00:56

    $(element).prop('disabled', true); //true|disabled will work on all
    $(element).attr('disabled', true); 
    element.disabled = true;
    element.setAttribute('disabled', true);
    

    All of the above are perfectly valid solutions. Choose the one that fits your needs best.

提交回复
热议问题