Add disabled attribute to input element using Javascript

后端 未结 7 613
执念已碎
执念已碎 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:54

    You can get the DOM element, and set the disabled property directly.

    $(".shownextrow").click(function() { 
      $(this).closest("tr").next().show()
              .find('.longboxsmall').hide()[0].disabled = 'disabled';
    });
    

    or if there's more than one, you can use each() to set all of them:

    $(".shownextrow").click(function() { 
      $(this).closest("tr").next().show()
              .find('.longboxsmall').each(function() {
                   this.style.display = 'none';
                   this.disabled = 'disabled';
              });
    });
    

提交回复
热议问题