Home  >  Article  >  Web Front-end  >  Summary of JQuery's methods of controlling radio selection and deselection_jquery

Summary of JQuery's methods of controlling radio selection and deselection_jquery

WBOY
WBOYOriginal
2016-05-16 16:03:541413browse

1. Setting the selection method

Copy code The code is 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(); //Get the Value value of the selected Radio

2. Example of setting selected and unselected

Copy code The code is as follows:

No
Yes
In #jquery, the selection of radio is set like this.
$("#rdo1").attr("checked","checked");
$("#rdo1").removeAttr("checked");

by name

Copy code The code is as follows:

$("input:radio[name="analyfsftype"]").eq(0).attr("checked",'checked');
$("input:radio[name="analyshowtype"]").attr("checked",false);

by id
Copy code The code is as follows:

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

3. Another setting selection method

Copy code The code is as follows:



Your gender:
Copy code The code is as follows:

checked/>Male
checked/>Female

4. Set the radio according to the value and select

Copy code The code is as follows:

$("input[name='radio_name'][value='Value to select Radio']").attr("checked",true); //Set Radio to the selected state according to the Value value

5. Examples of using the prop method

Copy code The code is as follows:

$('input').removeAttr('checked');
$($('#' id 'input').eq(0)).prop('checked',false);
$($('#' id ' input').eq(0)).prop('checked',true);

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn