这是我的 html 代码。
<form id="item">
<div class="form-group col-lg-3 col-md-3 col-sm-3 col-sx-3">
<label for="itemtype">Hotel</label>
<input type="radio" class="radio" id="itemtype" name="optradio" value="H" checked>
<label for="itemtype">AirPort</label>
<input type="radio" class="radio" id="itemtype" name="optradio" value="A">
</div>
</form>
这是我的 jquery。
function save() {
debugger
$.ajax({
type: "POST",
data: { "item": { "itemid": $("#itemid").val(), "itemtype": $('#itemtype').val() }},
url: "@Url.Action("Save", "Item")",
cache:false,
success: function (data) {
debugger
if (data.isSuccess) {
alert("Saved Succesfully!");
window.location.href = "@Url.Action("Index", "Item")";
}
}, error: function (err) {
alert("Saved Failed!")
debugger
}
});
}
当我尝试保存项目类型调用“A”时,它一直没有发生。此查询始终将单选按钮值设置为“H”。我需要传递第二个值“A”。
最佳答案
通过名称可以获取正确的值,请去掉重复的id
$('input[name=optradio]:checked', '#item').val()
关于javascript - 如何获取第二个定义的单选按钮值?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58485444/