【问题标题】:how can i get the selected asp radio button using jquery?如何使用 jquery 获取选定的 asp 单选按钮?
【发布时间】:2011-02-10 15:43:03
【问题描述】:

这是我的 aspx 代码,默认情况下我选择了第一个。如何在 Jquery 中获取值?

<asp:RadioButtonList runat="server" ID="rbDisType" RepeatDirection="Horizontal" CssClass="styleRadioButton">
<asp:ListItem Text="Sale" Value="True" Selected="True"></asp:ListItem>
<asp:ListItem Text="Damage" Value="False"></asp:ListItem>
</asp:RadioButtonList>

这是它的渲染代码..

 <table id="ctl00_ContentPlaceHolder1_rbDisType" class="styleRadioButton ui-buttonset" border="0">
    <tbody><tr>
        <td><input class="ui-helper-hidden-accessible" id="ctl00_ContentPlaceHolder1_rbDisType_0" name="ctl00$ContentPlaceHolder1$rbDisType" value="True" checked="checked" type="radio"><label aria-disabled="false" role="button" aria-pressed="false" class="ui-button ui-widget ui-state-default ui-button-text-only ui-corner-left" for="ctl00_ContentPlaceHolder1_rbDisType_0"><span class="ui-button-text">Sale</span></label></td>

<td><input class="ui-helper-hidden-accessible" id="ctl00_ContentPlaceHolder1_rbDisType_1" name="ctl00$ContentPlaceHolder1$rbDisType" value="False" type="radio"><label aria-disabled="false" role="button" class="ui-button ui-widget ui-state-default ui-button-text-only ui-corner-right ui-state-active" aria-pressed="true" for="ctl00_ContentPlaceHolder1_rbDisType_1"><span class="ui-button-text">Damage</span></label></td>
    </tr>
</tbody></table>

【问题讨论】:

  • 我在重新渲染时添加了代码。

标签: c# jquery radiobuttonlist


【解决方案1】:

试试这个:

$("input:radio[name$='rbDisType']").click(function(){
      alert($(this).val());
});

【讨论】:

    【解决方案2】:

    首先查看生成的代码,即查看浏览器接收的源代码。然后通过 ID,您可以使用 JQuery 轻松导航到那里并读出值,应该是这样的。

    $("#rbDisType").val()
    

    【讨论】:

      猜你喜欢
      • 2011-05-07
      • 1970-01-01
      • 1970-01-01
      • 2012-01-27
      • 2011-07-28
      • 1970-01-01
      • 1970-01-01
      • 2015-03-28
      相关资源
      最近更新 更多