獲取radio 選中的值

1.獲取選中值,三種方法都可以:

 

$('input:radio:checked').val();

 

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

 

$("input[name='id']: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');

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章