gpt4 book ai didi

c# - 尝试使用 ajax/jquery 获取所选单选按钮的值

转载 作者:行者123 更新时间:2023-11-30 12:44:23 25 4
gpt4 key购买 nike

我正在尝试获取使用 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>

最佳答案

将您的 HTML 更改为,我在此处添加了通用类 spacingCheckBox 到单选按钮

<fieldset>
<label for="doubleSpacingV">
Double Spacing
@Html.RadioButtonFor(model => model.spacing, "double", new { @class = "spacingCheckBox", @checked = true })
</label>
<label for="singleSpacingV">
Single Spacing
@Html.RadioButtonFor(model => model.spacing, "single", new { @class = "spacingCheckBox" })
</label>
@Html.ValidationMessageFor(model => model.spacing)
</fieldset>

要检索选中的复选框值,请使用

spacing: $('.spacingCheckBox:checked').val()

注意:我没有测试过

关于c# - 尝试使用 ajax/jquery 获取所选单选按钮的值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23126196/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com