Jquery sets the disabled element to enabled.

Source: Internet
Author: User
In jquery, you can use jqueryObj. attr (& quot; disabled & quot;, & quot; disabled & quot;) sets an element on the page to editable or trigger, however, the APIreference of jquery does not indicate how to set the page to disable to trigger or editable. Here we can use three workarounds to change the state of an element that is set to disabled to enabled.
First, change the boolean status of disabled. The code and explanation are as follows:

The Code is as follows:


$ ("Button: eq (2)"). click (function (){
Var text2 = $ ("input: text: eq (2 )");
If (text2.attr ("disabled") = false ){
// Set the disabled boolean attribute to true in the third text input box.
Text2.attr ("disabled", true );
} Else {
// Remove the disabled attribute by setting the disabled attribute of the third text input box to false.
Text2.attr ("disabled", false );
}
});


Method 2: remove the disabled attribute. The code and explanation are as follows:

The Code is as follows:


$ ("Button: eq (1)"). click (function (){
Var text2 = $ ("input: text: eq (1 )");
If (text2.attr ("disabled") = false ){
// Set the value of disabled to disabled in the second text input box.
Text2.attr ("disabled", "disabled ");
} Else {
// Remove the disable attribute of the second text input box.
Text2.removeAttr ("disabled ");
}
});


Third: Change the disabled value. The code and explanation are as follows:

The Code is as follows:


$ ("Button: eq (0)"). click (function (){
Var text1 = $ ("input: text: eq (0 )");
If (text1.attr ("disabled") = ""){
// Or text1.attr ("disabled") = false
// Set the value of disabled to disabled in the first text input box.
Text1.attr ("disabled", "disabled ");
} Else {
// Overwrite the disabled attribute in the first text input box.
Text1.attr ("disabled ","");
}
});


The complete sample code is as follows (tested ):

The Code is as follows:




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.