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

如何使用jquery或javascript获取单选按钮Id值,javascript,jquery,asp.net-mvc,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> <i

我有这个代码在我看来

<%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">
<% } %>
我无法获取我检查过的单选按钮Id。我正在上车,但我需要如何知道在我的视图中选择了哪个单选按钮


谢谢

为您的单选按钮赋予“值”属性:

<input type="radio" id="Default Selections" name="selection" value="default" />    
<input type="radio" id="Existing Selections" name="selection" value="existing" />

为单选按钮赋予“值”属性:

<input type="radio" id="Default Selections" name="selection" value="default" />    
<input type="radio" id="Existing Selections" name="selection" value="existing" />

您可以忘记单选按钮中的id和put-value属性,代码如下所示

<%using (Html.BeginForm("X", "Y", FormMethod.Post, new { @id = "XSS" }))
{ %>

   <fieldset>
       <legend>Select Selection Type</legend>

       <label>Default Selections:</label>
          <input type="radio" value="Default Selections" name="selection" />
          <br />
          <label>Existing Selections:</label>
          <input type="radio" value="Existing Selections" name="selection" />
   </fieldset>

   <input type="submit" value="submit">
<% } %>

您可以忘记单选按钮中的id和put-value属性,代码如下所示

<%using (Html.BeginForm("X", "Y", FormMethod.Post, new { @id = "XSS" }))
{ %>

   <fieldset>
       <legend>Select Selection Type</legend>

       <label>Default Selections:</label>
          <input type="radio" value="Default Selections" name="selection" />
          <br />
          <label>Existing Selections:</label>
          <input type="radio" value="Existing Selections" name="selection" />
   </fieldset>

   <input type="submit" value="submit">
<% } %>

此功能将为您提供所选单选按钮值及其Id

 $("input:radio[name=selection]").click(function() {
        var value = $(this).val();
        alert(value);
        var id= $(this).attr('id');
        alert(id);
    });

此功能将为您提供所选单选按钮值及其Id

 $("input:radio[name=selection]").click(function() {
        var value = $(this).val();
        alert(value);
        var id= $(this).attr('id');
        alert(id);
    });