簡體   English   中英

如何使用jquery獲取選定的asp單選按鈕?

[英]how can i get the selected asp radio button using jquery?

這是我的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>

試試這個:

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

首先查看生成的代碼,即查看瀏覽器接收的源。 然后通過ID可以輕松地使用JQuery導航到那里並讀出值,應該是這樣的。

$("#rbDisType").val()

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM