jquery method for setting element readonly and Disabled properties

Source: Internet
Author: User

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.

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.