1.<input type="radio" name="testradio" value="jquery獲取radio的值" />jquery獲取radio的值
2.<input type="radio" name="testradio" value="jquery獲取checkbox的值" />jquery獲取checkbox的值
3.<input type="radio" name="testradio" value="jquery獲取select的值" />jquery獲取select的值
要想獲取某個radio的值有以下的幾種方法,直接給出代碼:
1.$('input[name="testradio"]:checked').val();2、
1.$('input:radio:checked').val();3、
1.$('input[@name="testradio"][checked]');4、
1.$('input[name="testradio"]').filter(':checked');差不多挺全的了,如果我們要遍歷name為testradio的所有radio呢,代碼如下
1.$('input[name="testradio"]').each(function(){2.alert(this.value);3.});如果要取具體某個radio的值,比如第二個radio的值,這樣寫
1.$('input[name="testradio"]:eq(1)').val()
以上的是網上的,一下:
<table class="table table-bordered">
<thead>
<tr>
<th style="vertical-align:middle" class="text-center" rowspan="2">單選按鈕操作</th>
</tr>
</thead>
<tbody>
#foreach($item in [1,2,3,4,5])
<tr>
<td>
<input type="radio" name="audit$!{item}" value="1" checked>通過
<input type="radio" name="audit$!{item}" value="0">駁回
</td>
</tr>
</table>
以上動態的,每行都有一對單選radio,此時獲取選中的每行的值,則代碼如下:
$('input:radio:checked').each(function(){
//var checkValue = $(this).val();
console.log($(this).val()); // 選中框中的值
});