Jquery gets the value of radio of the radio group radio

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

Radio set radio: $(" input [@ type = radio] [@ checked] "). The val ();

Radio set radio: $(" input [@ type = radio] "). The attr (" checked ", '2'); // the item with value=2 is the currently selected item

Gets the values of a set of selected items of radio

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

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

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

Radio set radio: $(" input [@ type = radio] "). The attr (" checked ", '2'); // the item with value=2 is the currently selected item

The old version of jquery

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

Jquery 1.3 later

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

Take a jquery example that gets the value of radio


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();
(www.jb51.net) $("#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: