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:
Copy codeThe 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:Copy codeThe 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:Copy codeThe 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 ):
Copy codeThe Code is as follows: <! Doctype html public "-// W3C // dtd html 4.01 Transitional // EN" "http://www.w3.org/TR/html4/loose.dtd">
<Html>
<Head> <script src = "jquery path Introduction"> </script>
<Script type = "text/javascript"> <! --
$ (Document). ready (function (){
$ ("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 ","");
}
});
$ ("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 ");
}
});
$ ("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 );
}
});
});
// --> </Script>
</Head>
<Body>
<Button> disabledNull </button>
<Input type = "text" value = "input something into me! "Size =" 40 "/>
<Br/>
<Button> disabledRemove </button>
<Input type = "text" value = "input something into me! "Size =" 40 "/>
<Br/>
<Button> disabledState </button>
<Input type = "text" value = "input something into me! "Size =" 40 "/>
</Body>
</Html>