我試圖獲得使用ajax和jquery選擇哪個單選按鈕的值,但我只能做到以下,當然它只能工作如果該單選按鈕是否被選中。我究竟做錯了什麼?試圖獲得選定的單選按鈕使用ajax/jQuery的價值
$('#urgencyJList').change(function() {
var modelData = {
paperType: $("#paperTypeJList").val(),
urgency: $("#urgencyJList").val(),
numOfPages: $("#numOfPagesJList").val(),
**spacing: $("#doubleSpacingV").val()**
};
$.ajax({
url: '@Url.Action("getNewPrice","Home")',
data: modelData,
type: "POST",
cache: false,
async: true,
success: function (response) {
document.getElementById('priceLabel').innerHTML = response;
}
});
});
我的單選按鈕,代碼如下:
<div class="row">
@Html.LabelFor(model => model.spacing, "Spacing:")
<fieldset>
<label for="doubleSpacingV">
Double Spacing
@Html.RadioButtonFor(model => model.spacing, "double", new { id = "doubleSpacingV", @checked = true })
</label>
<label for="singleSpacingV">
Single Spacing
@Html.RadioButtonFor(model => model.spacing, "single", new { id = "singleSpacingV" })
</label>
@Html.ValidationMessageFor(model => model.spacing)
</fieldset>
</div>
我剛剛用創建單選按鈕的代碼編輯它 –
我該如何使用我的代碼?沒有辦法獲得任何單選按鈕的檢查價值嗎? –