Use jQuery to set the disabled attribute and remove the disabled attribute, jquerydisabled
Differences between readOnly and disabled in a form:
Readonly is only valid for input (text/password) and textarea, while disabled is valid for all form elements, including select, radio, checkbox, And button.
However, after a form element is disabled, when we submit the form in POST or GET mode, the value of this element will not be passed out, readonly will pass this value out (this occurs when we set the textarea element in a form to disabled or readonly, but the submitbutton is usable ).
Js operations:
Copy codeThe Code is as follows:
Function disableElement (element, val ){
Document. getElementById (element). disabled = val;
}
JQuery:
Copy codeThe Code is as follows:
// Set the disabled attribute in two ways
$ ('# AreaSelect'). attr ("disabled", true );
$ ('# AreaSelect'). attr ("disabled", "disabled ");
// Remove the disabled attribute in three ways
$ ('# AreaSelect'). attr ("disabled", false );
$ ('# AreaSelect'). removeAttr ("disabled ");
$ ('# AreaSelect'). attr ("disabled ","");
Get s: textfield and set its disabled attribute:
Copy codeThe Code is as follows:
FunctiondisableTextfieldofAccountDiv (element, val ){
$ (Element). find (": textfield"). attr ('Disabled ', val );
}
Why does jquery set the attribute of checkbox disabled useless?
Attr ('Disabled ', 'Disabled ');
RemoveAttr ('Disabled ');
Why is it difficult to set checkebox disabled in jquery?
Hello !!
This disabled attribute is disabled when it is put on ··
What do you mean is not easy to use?
JQuery can use the prop () function to control attributes such as disabled checked.
For example: $ ("input [name = 'role0121 ']"). prop ("disabled", true );
For this disabled attribute, you cannot control whether to enable or disable the string spelling method ··
Enable the disabled attribute <input type = "checkbox" disabled = "disabled"/>
Disable the disabled attribute. You must delete disabled, that is, <input type = "checkbox"/>