iT邦幫忙

8

jQuery取Radio的值

官方網站上沒有文件介紹該如何取得Form元素Radio哪個被選取的方法。

感謝Google大神再次賜給我們解答。

$('input[name=radio使用的name的值]:checked').val()

就是這麼簡單,收工。


圖片
  直播研討會
圖片
{{ item.channelVendor }} {{ item.webinarstarted }} |
{{ formatDate(item.duration) }}
直播中
0

有沒有前後與使用的範例可以供想像或應證?!
^o^

1
fillano
iT邦超人 1 級 ‧ 2009-04-14 13:37:43

簡單的例子:

<pre class="c" name="code">

<script type="text/javascript" src="js/jquery-1.3.2.min.js"></script>

<form onsubmit="alert($('input[name=radio1]:checked').val());return false;">
<input type="radio" name="radio1" value="1">1<br/>
<input type="radio" name="radio1" value="2">2<br/>
<input type="radio" name="radio1" value="3">3<br/>
<input type="submit">
</form>
0
wordsmith
iT邦高手 1 級 ‧ 2009-04-14 15:15:52

謝謝fillano大大舉的例子,簡單又能說明。

邦友如果想試試看,本地端又沒有jQuery的檔案,可以指向下面的網址:

<pre class="c" name="code"><script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.2.6/jquery.min.js"></script>

我要留言

立即登入留言