Home >Web Front-end >JS Tutorial >Use jQuery to set disabled attributes and remove disabled attributes_jquery

Use jQuery to set disabled attributes and remove disabled attributes_jquery

WBOY
WBOYOriginal
2016-05-16 16:39:051389browse

The difference between readOnly and disabled in the form:

Readonly is only valid for input (text/password) and textarea, while disabled is valid for all form elements, including select, radio, checkbox, button, etc.

But after the form element is disabled, when we submit the form by POST or GET, the value of this element will not be passed out, and readonly will pass the value out (this situation occurs when we Set the textarea element in a form to disabled or readonly, but the submit button can be used).

js operation:

Copy code The code is as follows:

function disableElement(element,val){

document.getElementById(element).disabled=val;

}


jQuery to operate:
Copy code The code is as follows:

//Two methods to set the disabled attribute
$('#areaSelect').attr("disabled",true);
$('#areaSelect').attr("disabled","disabled");

//Three methods to remove the disabled attribute
$('#areaSelect').attr("disabled",false);
$('#areaSelect').removeAttr("disabled");
$('#areaSelect').attr("disabled","");


Get s:textfield and set its disabled attribute:
Copy code The code is as follows:

functiondisableTextfieldofAccountDiv(element,val) {

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

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn