As jquery becomes more and more useful, more and more friends are used. In the web, the use of controls such as CheckBox, Radiobutton, DropDownList, and so on, is related to the operational problems of these controls in jquery. Since the version of jquery has been updated quickly and the code has changed a lot, the following jquery code is query1.4 version.
1. Get the selected value, three methods can be:
Copy Code code as follows:
$ (' input:radio:checked '). Val ();
$ ("input[type= ' Radio ']:checked"). Val ();
$ ("Input[name= ' rd ']:checked"). Val ();
2. Set the first radio to the selected value:
Copy Code code as follows:
$ (' Input:radio:first '). attr (' checked ', ' checked ');
Or
Copy Code code as follows:
$ (' Input:radio:first '). attr (' checked ', ' true ');
Note: attr ("Checked", ' checked ') = attr ("Checked", ' true ') = attr ("Checked", true)
3. Set the last radio to the selected value:
Copy Code code as follows:
$ (' Input:radio:last '). attr (' checked ', ' checked ');
Or
Copy Code code as follows:
$ (' Input:radio:last '). attr (' checked ', ' true ');
4. Set any one radio to the selected value based on the index value:
Copy Code code as follows:
$ (' Input:radio '). EQ (index value). attr (' checked ', ' true '); index value =0,1,2 ....
Or
Copy Code code as follows:
$ (' Input:radio '). Slice (1,2). attr (' checked ', ' true ');
5. Set Radio to selected value according to value
Copy Code code as follows:
$ ("input:radio[value= ' Rd2 ']"). attr (' checked ', ' true ');
Or
Copy Code code as follows:
$ ("input[value= ' Rd2 ']"). attr (' checked ', ' true ');
6. Delete the radio value of RD2
Copy Code code as follows:
$ ("input:radio[value= ' Rd2 ']"). Remove ();
7. Delete the first few radio
Copy Code code as follows:
$ ("Input:radio"). EQ (index value). Remove (); index value =0,1,2 ....
such as delete 3rd radio:$ ("Input:radio"). EQ (2). Remove ();
8. Traverse Radio
Copy Code code as follows:
$ (' Input:radio '). each (function (Index,domele) {
Write code
});