Jquery gets an instance of a radio value

  • 2020-03-30 04:09:58
  • OfStack

This article is an example of how to get the value of radio from jquery. The details are as follows:

Radio group:

$("input[@type=radio][@checked]").val();

Radio group:

$("input[@type=radio]").attr("checked",'2');// Set up the value=2 Is the currently selected item 

Gets the values of a set of selected items of radio

var item = $('input[@name=items][@checked]').val();

The second element of the radio radio group is the currently selected value

$('input[@name=items]').get(1).checked = true

The old version of jquery

var_name = $("input[@name='radio_name']:checked").val();

Jquery 1.3 later
var_name = $("input[name='radio_name']:checked").val();

Get a jquery instance of the radio value:

function getra(){
var_name = $("input[name='isspecialcnt']:checked").val();
//alert(var_name);
if(var_name=='1'){
$("#isspecialcntyes").show();
$("#isspecialcntno").hide();
}
if(var_name=='0'){
$("#isspecialcntyes").hide();
$("#isspecialcntno").show();
}
} <form name="form1" method="post" action="">
<p>
<label>
<input type="radio" name="radiogroup1" value=" The radio " id="radiogroup1_0">
The radio </label>
<br>
<label>
<input type="radio" name="radiogroup1" value=" The radio " id="radiogroup1_1">
The radio </label>
<br>
<label>
<input type="radio" name="radiogroup1" value=" The radio " id="radiogroup1_2">
The radio </label>
<br>
<label>
<input type="radio" name="radiogroup1" value=" The radio " id="radiogroup1_3">
The radio </label>
<br>
<label>
<input type="radio" name="radiogroup1" value=" The radio " id="radiogroup1_4">
The radio </label>
<br>
<label>
<input type="radio" name="radiogroup1" value=" The radio " id="radiogroup1_5">
The radio </label>
<br>
</p>
</form>


Related articles: