четверг, 9 декабря 2010 г.

jQuery - как получить value radio элемента

Код - пример #1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
// ========= 1 вариант ==========
Cтрана: <br />
<input type="radio" name="country" value="Russia" checked="checked">Россия <br />
<input type="radio" name="country" value="Other">Другая

...

var the_value = $(":radio[name=country]").filter(":checked");

// ========= 2 вариант ==========
<form id="radio_form">
  <fieldset>
    <label><input type="radio" name="color" value="red" checked="checked" />Red</label><br />
    <label><input type="radio" name="color" value="yellow" />Yellow</label><br />    
    <label><input type="radio" name="color" value="blue" />Blue</label><br />
    <label><input type="radio" name="color" value="purple" />Purple</label><br />
  </fieldset>
</form>

...

var the_value = $('#radio_form input:radio:checked').val();

Комментариев нет:

Отправить комментарий