Share the next jquery setting element readonly and Disabled properties, set the element's display and hide, and the element's read-only property.
The following: http://www.jbxue.com/article/15102.html slightly modified and supplemented.
The jquery API provides a way to apply disabled and ReadOnly attributes to elements:
1, setting the ReadOnly property
$ (' input '). attr ("ReadOnly", "ReadOnly")//set the INPUT element to ReadOnly$ (' input '). Removeattr ("ReadOnly");//removing the readonly attribute of the INPUT elementif($ (' input '). attr ("readonly") = =true)//determines whether the INPUT element has the ReadOnly property setThere are two ways to set the ReadOnly property for an element and to cancel the ReadOnly property: $ (' input '). attr ("ReadOnly",true)//set the INPUT element to ReadOnly$ (' input '). attr ("ReadOnly",false)//removing the readonly attribute of the INPUT element$(' input '). attr ("ReadOnly", "ReadOnly")//set the INPUT element to ReadOnly$ (' input '). attr ("ReadOnly", "" ")//removing the readonly attribute of the INPUT element
2, setting the Disabled property
$ (' input '). attr ("Disabled", "disabled")//set the INPUT element to disabled$ (' input '). Removeattr ("Disabled");//removing the disabled attribute of the INPUT elementif($ (' input '). attr ("disabled") = =true)//determines whether the INPUT element has the Disabled property setThere are two ways to set the disabled property for an element and to cancel the Disabled property: $ (' input '). attr ("Disabled",true)//set the INPUT element to disabled$ (' input '). attr ("Disabled",false)//removing the disabled attribute of the INPUT element$(' input '). attr ("Disabled", "disabled")//set the INPUT element to disabled$ (' input '). attr ("Disabled", "" ")//removing the disabled attribute of the INPUT element
Reference Links:
- jquery set element readonly and disabled properties
- jquery sets the ReadOnly and disabled properties of elements
In the second part, jquery operates three methods of disabled properties.
First: Change the Boolean state of the disabled:
$ ("Button:eq (2)"). Click (functionvar text2=$ ("Input:text:eq (2)"if( Text2.attr ("disabled") = =false//text2.attr ("Disabled",true);} Else //text2.attr ("Disabled",false);});
The second type: Remove the Disabled property:
$ ("Button:eq (1)"). Click (functionvar text2=$ ("Input:text:eq (1)"if( Text2.attr ("disabled") = =false//text2.attr ("Disabled", "disabled");} Else //text2.removeattr ("Disabled");});
The Third Kind: Change the value of disabled
$ ("Button:eq (0)"). Click (functionvar text1=$ ("input:text:eq (0)"if( Text1.attr ("disabled") = = ""////Text1.attr ("Disabled", "disabled" ); }Else//text1.attr ("Disabled", "");});
If you have time, then look at jquery to set the elements readonly and disabled (checkbox read-only) method.