我有这段代码。
<%using (Html.BeginForm("X", "Y", FormMethod.Post, new { @id = "XSS" }))
{ %>
<fieldset>
<legend>Select Selection Type</legend>
<label>Default Selections:</label>
<input type="radio" id="Default Selections" name="selection" />
<br />
<label>Existing Selections:</label>
<input type="radio" id="Existing Selections" name="selection" />
</fieldset>
<input type="submit" value="submit">
<% } %>
在我的 Controller post Action 结果中,我试图获取我正在做的这个选择的值
collection["selection"]
我无法获得我检查过的单选按钮 ID。我正在“开启”,但我如何知道在我的 View 中选择了哪个单选按钮?
谢谢
最佳答案
此函数将为您提供选定的单选按钮值及其 ID。
$("input:radio[name=selection]").click(function() {
var value = $(this).val();
alert(value);
var id= $(this).attr('id');
alert(id);
});
关于javascript - 如何使用 jquery 或 javascript 获取单选按钮 Id 值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6130116/