JQuery controls the radio selected and unselected method summary

  • 2020-05-30 19:22:23
  • OfStack

1. Set the selected method


$("input[name=' The name ']").get(0).checked=true;
$("input[name=' The name ']").attr('checked','true');
$("input[name=' The name ']:eq(0)").attr("checked",'checked');
$("input[name='radio_name'][checked]").val();  // Get selected Radio the Value value

2. Set the selected and unselected examples


<input type="radio" value="0" name="jizai" id="0"/> no
<input type="radio" value="1" name="jizai"  id="1"/> is
#jquery , radio Is set in this way.
$("#rdo1").attr("checked","checked");
$("#rdo1").removeAttr("checked");

Through name


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

Through id

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

3. Another setting selection method


<script type="text/javascript"> 
$(document).ready(function(){ 
        $("input[@type=radio][name=sex][@value=1]").attr("checked",true); 
}); 
</script> 

Your gender:

<input type="radio" name="sex" value="1" <s:if test="user.sex==1">checked</s:if>/> male  
<input type="radio" name="sex" value="0" <s:if test="user.sex==0">checked</s:if>/> female

4. Select radio according to the value


$("input[name='radio_name'][value=' To select the Radio the Value value ']").attr("checked",true);  // According to the Value Value is set Radio For selected state

5. Use the prop method to manipulate the example


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


Related articles: