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: