我有以下的HTML代碼:jQuery的.VAL()不爲單選按鈕的工作
<form id="attorneyRegisterForm">
<div class="captchaIcons">
<label class="yourAgeLabel" for="rdo_1">
<input
type="radio"
class="yourAgeRadio"
id="rdo_1"
name="attorneyRegister_age"
value="43b5b5755010e47acf5d549de05a205d"
title="Moon"
/>
<i class="icon-moon ageIcons" title="Moon"></i>
</label>
...
<label class="yourAgeLabel" for="rdo_X">
<input
type="radio"
class="yourAgeRadio"
id="rdo_X"
name="attorneyRegister_age"
value="c56f8bd55a15392e1039461c8006385c"
title="Flag"
/>
<i class="icon-flag ageIcons" title="Flag"></i>
</label>
</div>
<a href="#" id="registerAttorneyButton" class="button primary tiny">
<?php
_e('Register', 'z');
?>
</a>
</form>
,在我的JavaScript文件我有以下代碼:
var $attorneyRegisterForm = $('#attorneyRegisterForm');
var $attorneySubmitForm = $('a#registerAttorneyButton');
var $attorneyNonce = $('#attorneyNonce');
var $attorneyFirstName = $('#attorney_first_name');
var $attorneyLastName = $('#attorney_last_name');
var $attorneyEmail = $('#attorney_email');
var $attorneyPassword = $('#attorney_password');
var $attorneyPasswordConfirm = $('#attorney_password_confirm');
var $yourAgeRadio = $('#attorneyRegisterForm input[type="radio"]');
if($attorneyRegisterForm.length > 0)
{
$attorneyRegisterForm.on(
'submit.attorney',
function(e)
{
$data = {
fName : $attorneyFirstName.val(),
lName : $attorneyLastName.val(),
email : $attorneyEmail.val(),
pass : $attorneyPassword.val(),
passC : $attorneyPasswordConfirm.val(),
age : $yourAgeRadio.val(),
s : $attorneyNonce.val()
};
console.log($data);
e.preventDefault();
}
);
$attorneySubmitForm.on(
'click',
function(e)
{
$attorneyRegisterForm.submit();
e.preventDefault();
}
);
}
現在的問題當我從HTML表單中選擇radio
時,jQuery總是返回第一個radion值,而不是所選的值。
我的javascript錯了嗎?或者我應該嘗試另一種方法來檢索單選按鈕?
使用':checked'選項來獲得所選擇的單選按鈕 –