1.獲取選中值,三種方法都可以:
$('input:radio:checked').val();
$("input[type='radio']:checked").val();
$("input[name='rd']:checked").val();
2.設置第一個Radio爲選中值:
$('input:radio:first').attr('checked', 'checked');
或者
$('input:radio:first').attr('checked', 'true');
注:attr("checked",'checked')= attr("checked", 'true')= attr("checked", true)
3.設置最後一個Radio爲選中值:
$('input:radio:last').attr('checked', 'checked');
或者
$('input:radio:last').attr('checked', 'true');
4.根據索引值設置任意一個radio爲選中值:
$('input:radio').eq(索引值).attr('checked', 'true');索引值=0,1,2....
或者
$('input:radio').slice(1,2).attr('checked', 'true');
5.根據Value值設置Radio爲選中值
$("input:radio[value=http://www.2cto.com/kf/201110/'rd2']").attr('checked','true');
或者
$("input[value=http://www.2cto.com/kf/201110/'rd2']").attr('checked','true');
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、
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()