Use jQuery to set the disabled attribute and remove the disabled attribute, jquerydisabled

Source: Internet
Author: User

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"/>

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.