Jquery 獲取 radio選中值

2021-06-07 13:54:17 字數 1889 閱讀 6161

radio

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='rd2']").attr('checked','true');

或者$("input[value='rd2']").attr('checked','true');

6.刪除value值為rd2的radio

$("input:radio[value='rd2']").remove();

7.刪除第幾個radio

$("input:radio").eq(索引值).remove();索引值=0,1,2....

如刪除第3個radio:$("input:radio").eq(2).remove();

8.遍歷radio

1.   獲取選中項:

獲取選中項的value值:

$('select#sel option:selected').val();

或者$('select#sel').find('option:selected').val();

獲取選中項的text值:

$('select#seloption:selected').text();

或者$('select#sel').find('option:selected').text();

2.   獲取當前選中項的索引值:

$('select#sel').get(0).selectedindex;

3.   獲取當前option的最大索引值:

$('select#sel option:last').attr("index")

4.   獲取dropdownlist的長度:

$('select#sel')[0].options.length;

或者$('select#sel').get(0).options.length;

5.  設定第乙個option為選中值:

$('select#sel option:first').attr('selected','true')

或者$('select#sel')[0].selectedindex = 0;

6.   設定最後乙個option為選中值:

Jquery 獲取 radio選中值

radio 1.獲取選中值,三種方法都可以 input radio checked val 這種方式親測不行 input type radio checked val input name rd checked val 2.設定第乙個radio為選中值 input radio first attr ...

Jquery 獲取 radio選中值

隨著jquery的作用越來越大,使用的朋友也越來越多。在web中,由於checkbox radiobutton dropdownlist等控制項使用的頻率比較高,就關係到這些控制項在jquery中的操作問題。由於jquery的版本更新很快,的寫法也改變了許多,以下jquery 適query1.4版本...

Jquery 獲取 radio選中值

radio 1.獲取選中值,三種方法都可以 input radio checked val input type radio checked val input name rd checked val 2.設定第乙個radio為選中值 input radio first attr checked c...