Set and remove the disabled property using jQuery

  • 2020-03-30 03:44:25
  • OfStack

The difference between readOnly and disabled in the form:

Readonly works only for input(text/ password) and textarea, while disabled works for all form elements, including select,radio, checkbox, button, and so on.

However, after the form element USES disabled, when we submit the form in POST or GET mode, the value of this element will not be passed, and readonly will pass the value (this happens when we set the textarea element in a form to disabled or readonly, but the submitbutton can be used).

Js operation:


function disableElement(element,val){ document.getElementById(element).disabled=val; }

JQuery operates:

//There are two ways to set the disabled property
$('#areaSelect').attr("disabled",true);
$('#areaSelect').attr("disabled","disabled"); //Three methods remove the disabled attribute
$('#areaSelect').attr("disabled",false);
$('#areaSelect').removeAttr("disabled");
$('#areaSelect').attr("disabled","");

Gets s:textfield and sets its disabled property:

functiondisableTextfieldofAccountDiv(element,val) { $(element).find(":textfield").attr('disabled',val);
}


Related articles: