This article mainly introduces the jquery radio (radio button) Operation method Summary, this article explains to get the selected value, set the selected value, based on value values set selected, delete radio, traverse and other content, the need for friends can refer to the following
As jquery has become more and more important, more and more friends are being used. In the web, because controls such as checkboxes, Radiobutton, DropDownList, and so on are used more frequently, they are related to the operation of these controls in jquery. Since the version of jquery is updated very quickly, the code has changed a lot, the following jquery code is suitable for query1.4 version above.
1. To get the selected value, three methods are available:
Copy CodeThe code is 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 CodeThe code is as follows:
$ (' Input:radio:first '). attr (' checked ', ' checked ');
Or
Copy CodeThe code is as follows:
$ (' Input:radio:first '). attr (' checked ', ' true ');
Note: attr ("Checked", ' checked ') = attr ("Checked", ' true ') = attr ("Checked", true)
3. Set the last radio as the selected value:
Copy CodeThe code is as follows:
$ (' Input:radio:last '). attr (' checked ', ' checked ');
Or
Copy CodeThe code is as follows:
$ (' Input:radio:last '). attr (' checked ', ' true ');
4. Set any one of the radio to the selected value according to the index value:
Copy CodeThe code is as follows:
$ (' Input:radio '). EQ (index value). attr (' checked ', ' true '); index value =0,1,2 ....
Or
Copy CodeThe code is as follows:
$ (' Input:radio '). Slice. attr (' checked ', ' true ');
5. Set Radio to the selected value based on value
Copy CodeThe code is as follows:
$ ("input:radio[value= ' Rd2 ')"). attr (' checked ', ' true ');
Or
Copy CodeThe code is as follows:
$ ("input[value= ' Rd2 ')"). attr (' checked ', ' true ');
6. Remove Radio with value Rd2
Copy CodeThe code is as follows:
$ ("input:radio[value= ' Rd2 ')". Remove ();
7. Delete the first few radio
Copy CodeThe code is as follows:
$ ("Input:radio"). EQ (index value). Remove (); index value =0,1,2 ....
such as removing the 3rd radio:$ ("Input:radio"). EQ (2). Remove ();
8. Traverse Radio
Copy CodeThe code is as follows:
$ (' Input:radio '). each (function (Index,domele) {
Write code
});
JQuery Radio (radio button) how-to Summary