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> |