Получения значения радиокнопки
Как мне получить допустим в переменную X значения активной радиокнопки по средствам jquery
<div id="discount_cal">
<input name="discount" type="radio" checked value="1">Без скидки |
<input name="discount" type="radio" value="5">5% скидка |
<input name="discount" type="radio" value="10">10% скидка |
<input name="discount" type="radio" value="20">20% скидка |
<input name="discount" type="radio" value="30">30% скидка
</div>
:help: |
hardware,
:-?
<!DOCTYPE HTML>
<html>
<head>
<title>Untitled</title>
<meta charset="utf-8">
<script src="http://code.jquery.com/jquery-latest.js"></script>
</head>
<body>
<div id="discount_cal">
<input name="discount" type="radio" checked value="1">Без скидки |
<input name="discount" type="radio" value="5">5% скидка |
<input name="discount" type="radio" value="10">10% скидка |
<input name="discount" type="radio" value="20">20% скидка |
<input name="discount" type="radio" value="30">30% скидка
</div>
<script>
var $cal = $('#discount_cal'),$dis = $('[name=discount]'),
foo = function ()
{
alert($(':checked',$cal).val())
};
foo();
$cal.on('click', $dis, foo)
</script>
</body>
</html>
|
Спасибо
|
решение без jQuery
<body>
<div id="discount_cal">
<input name="discount" type="radio" checked value="1">Без скидки |
<input name="discount" type="radio" value="5">5% скидка |
<input name="discount" type="radio" value="10">10% скидка |
<input name="discount" type="radio" value="20">20% скидка |
<input name="discount" type="radio" value="30">30% скидка</div>
<script>
discount_cal.onclick = function (e) {
e = e || window.event;
target = e.target || e.srcElement;
if (target.tagName != "INPUT") return;
alert(target.value);
}
</script>
</body>
|
| Часовой пояс GMT +3, время: 16:41. |