欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

jQuery獲取選中單選按鈕radio的值

 更新時(shí)間:2016年12月27日 10:38:15   作者:wbliu001  
本文給大家分享兩段實(shí)例代碼給大家講解jquery獲取選中單選按鈕radio的值,非常不錯(cuò),具有參考借鑒價(jià)值,一起看看吧

  實(shí)例1:

<div id="wrap">
  <input type="radio" name="payMethod" value="1" />男
  <input type="radio" name="payMethod" value="2" />女
</div>

  獲取一組單選按鈕對(duì)象:var obj_payPlatform = $('#wrap input[name="payMethod"]');

  獲取被選中按鈕的值 :var val_payPlatform = $('#wrap input[name="payMethod"]:checked ').val();

實(shí)例2:

使用jquery獲取radio的值,最重要的是掌握jquery選擇器的使用,在一個(gè)表單中我們通常是要獲取被選中的那個(gè)radio項(xiàng)的值,所以要加checked來篩選,比如有以下的一些radio項(xiàng):

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的值

要想獲取某個(gè)radio的值有以下的幾種方法,直接給出代碼:

1、

$('input[name="testradio"]:checked').val();
$('input:radio:checked').val();
$('input[@name="testradio"][checked]');
$('input[name="testradio"]').filter(':checked');

差不多挺全的了,如果我們要遍歷name為testradio的所有radio呢,代碼如下

$('input[name="testradio"]').each(function(){2.alert(this.value);3.});

如果要取具體某個(gè)radio的值,比如第二個(gè)radio的值,這樣寫

$('input[name="testradio"]:eq(1)').val()

以上所述是小編給大家介紹的jQuery獲取選中單選按鈕radio的值,希望對(duì)大家有所幫助,如果大家有任何疑問請(qǐng)給我留言,小編會(huì)及時(shí)回復(fù)大家的。在此也非常感謝大家對(duì)腳本之家網(wǎng)站的支持!

相關(guān)文章

最新評(píng)論