Home  >  Article  >  Web Front-end  >  jquery gets radio value (radio group radio)_javascript skills

jquery gets radio value (radio group radio)_javascript skills

WBOY
WBOYOriginal
2016-05-16 16:33:411327browse

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

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

Get the value of a set of radio selected items

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

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

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

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

Old version of jquery

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

jquery 1.3 and later versions

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

Look at a jquery example of getting 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();
(www.jb51.net) $("#isspecialcntno").show();
}
}

<form name="form1" method="post" action="">
<p>
<label>
<input type="radio" name="radiogroup1" value="单选" id="radiogroup1_0">
单选</label>
<br>
<label>
<input type="radio" name="radiogroup1" value="单选" id="radiogroup1_1">
单选</label>
<br>
<label>
<input type="radio" name="radiogroup1" value="单选" id="radiogroup1_2">
单选</label>
<br>
<label>
<input type="radio" name="radiogroup1" value="单选" id="radiogroup1_3">
单选</label>
<br>
<label>
<input type="radio" name="radiogroup1" value="单选" id="radiogroup1_4">
单选</label>
<br>
<label>
<input type="radio" name="radiogroup1" value="单选" id="radiogroup1_5">
单选</label>
<br>
</p>
</form>
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