jquery Control Radio Check and uncheck Method summary _jquery

Source: Internet
Author: User

First, set the selection method

Copy Code code as follows:

$ ("Input[name= ' name ']"). Get (0). Checked=true;
$ ("Input[name= ' name ']"). attr (' checked ', ' true ');
$ ("Input[name= ' name ']:eq (0)"). attr ("Checked", ' checked ');
$ ("Input[name= ' Radio_name '][checked]"). Val (); Gets the value of the selected radio

Two, set check and uncheck sample

Copy Code code as follows:

<input type= "Radio" value= "0" name= "Jizai" id= "0"/> No
<input type= "Radio" value= "1" name= "Jizai" id= "1"/> is
#jquery中, the radio is set in this way.
$ ("#rdo1"). attr ("Checked", "checked");
$ ("#rdo1"). Removeattr ("checked");

By name

Copy Code code as follows:

$ ("input:radio[name=" Analyfsftype "]"). EQ (0). attr ("Checked", ' checked ');
$ ("input:radio[name=" Analyshowtype "]"). attr ("checked", false);

by ID
Copy Code code as follows:

$ ("#tradeType0"). attr ("Checked", "checked");
$ ("#tradeType1"). attr ("checked", false);

Third, another set selection method

Copy Code code as follows:

<script type= "Text/javascript" >
$ (document). Ready (function () {
$ ("input[@type =radio][name=sex][@value =1]"). attr ("Checked", true);
});
</script>

Your sex:
Copy Code code as follows:

<input type= "Radio" name= "Sex" value= "1" <s:if test= "user.sex==1" >checked</s:if>/> Male
<input type= "Radio" name= "Sex" value= "0" <s:if test= "user.sex==0" >checked</s:if>/>

Four, according to the value set radio selected

Copy Code code as follows:

$ ("Input[name= ' radio_name '][value= ' to select Radio value ']"). attr ("Checked", true); Set Radio as selected based on value values

V. Using the Prop method to manipulate the sample

Copy Code code as follows:

$ (' input '). Removeattr (' checked ');
$ (' # ' +id+ ' input '). EQ (0)). Prop (' checked ', false);
$ (' # ' +id+ ' input '). EQ (0)). Prop (' checked ', true);

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.