JQuery introduction to getting and setting a single queue instance

Source: Internet
Author: User

Radio Group radio is a common html control in html. Next I will introduce you to getting and setting the single-Choice Program code in jquery. For more information, see.

Radio Group radio: $ ("input [@ type = radio] [@ checked]"). val ();

Obtains the value of a set of radio selected items.
Var item = $ ("input [@ name = items] [@ checked]"). val ();
Obtain the text of the selected select item.
Var item = $ ("select [@ name = items] option [@ selected]"). text ();
The second element in the select drop-down box is the selected value.
$ ("# Select_id") [0]. selectedIndex = 1;
The second element of the radio Group is the currently selected value.
$ ("Input [@ name = items]"). get (1). checked = true;

Set Radio Group Value

Radio Group radio: $ ("input [@ type = radio]"). attr ("checked", "2"); // set the project with value = 2 to the current selected item (error

)
$ ("Input [@ name = radio_s] [@ value = 16]"). attr ("checked", true); (tested)


Example 1

The Code is as follows: Copy code

<Asp: RadioButtonList runat = "server" ID = "rblShow" class = "show"

RepeatDirection = "Horizontal">

<Asp: ListItem Text = "yes" value = "1"/>

<Asp: ListItem Text = "no" value = "0"/>

</Asp: RadioButtonList>

<P class = "isShow" style = "width: 500px">
Test text
</P>

Then add Jquery reference in script js.

The Code is as follows: Copy code


<Script type = "text/javascript">
$ (Function (){
$ (": Radio"). click (function (){
If ($ (this). val () = "1 "){
$ (". IsShow"). fadeIn ();
} Else {
$ (". IsShow"). fadeOut ();
}
})
})

Example 2

The Code is as follows: Copy code

<Html>
<Head>
<Script type = "text/javascript" src = "/ajaxjs/jquery1.3.2.js">
</Script>
<Script type = "text/javascript">
$ (Function (){
$ ("# Form1"). submit (function (){

If ($ ("# form1 input: checked ")){
Alert ($ ("# form1 input: checked"). val ());
}

Return false; // do not submit
});
});
</Script>
<Title> Single-region test </title>
</Head>
<Body>
<Form id = "form1">
<Input type = "radio" name = "items" id = "item1" value = "a"/>
<Br/>
<Input type = "radio" name = "items" id = "item2" value = "B"/> B
<Br/>
<Input type = "radio" name = "items" id = "item3" value = "c"/> C
<Br/>
<Input type = "radio" name = "items" id = "item4" value = "d"/> D
<Br/>
<Input type = "radio" name = "items" id = "item5" value = "e"/> E
<Br/>
<Input type = "radio" name = "items" id = "item6" value = "f"/> F
<Br/>
<Input type = "radio" name = "items" id = "item7" value = "g"/> G
<Br/>
<Input type = "radio" name = "items" id = "item8" value = "h"/> H
<Br/>
<Input type = "submit" id = "btn1">
</Form>
</Body>
</Html>

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.