javascript - 如何使用 jquery 或 javascript 获取单选按钮 Id 值

标签 javascript jquery asp.net-mvc

我有这段代码。

<%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/

相关文章:

javascript - 使用过滤器更新 ng-repeat

javascript - Jquery滚动到没有Id的元素,仅通过数据属性

javascript - 如何使用其标签名称获取特定元素?

javascript - 在新选项卡中打开 Squarespace 幻灯片画廊

javascript - Dojo - 输入字段未附加到网格

javascript - AngularJS - 找不到 Controller

jquery - 使用 Pyramid 处理 ajax 文件上传服务器端

asp.net-mvc - Web Api 调用在服务器上返回 404

asp.net-mvc - .NET MVC MultiSelectList 和选定的值

c# - 为什么我的 Razor 'RenderSection' 没有被孙 View 继承?