gpt4 book ai didi

javascript - 如果选择了其中之一,则禁用 Asp.net RadioButtonList 中的其他 RadioButton

转载 作者:行者123 更新时间:2023-11-27 22:42:00 32 4
gpt4 key购买 nike

当选择其中一个时,我需要禁用其他 asp.net 单选按钮。共有三个单选按钮。例如选择了“现金”单选按钮,应禁用列表项中的其他两个。我做了一些研究,并且当选择第三个时,确实禁用了另外两个。但是在我的代码隐藏页面上,它为选定的单选按钮提供了空值。这是我的代码:

我的.aspx

 <div class="col-sm-4" style="padding-top:4px ; margin-top:-8px">
<asp:RadioButtonList runat="server" ID="loanTypeCheck" CssClass="pull-right" RepeatDirection="Horizontal">
<asp:ListItem Value="Cash" Text="&nbsp;&nbsp;Cash&nbsp;&nbsp;"/>
<asp:ListItem Value="Non-Cash" Text="&nbsp;&nbsp;Non-Cash&nbsp;&nbsp;" />
<asp:ListItem Value="Dharauti" Text="&nbsp;&nbsp;Dharauti&nbsp;&nbsp;" />

</asp:RadioButtonList>
</div>

我的代码背后

protected void SaveButton_Click(object sender, EventArgs e)
{
if (IsFormValidForSave())
{
var loanReceipt = GetLoanReceiptFromForm();
var transactionsDetails = new List<TransactionDetail>();

if (loanTypeCheck.SelectedValue == "Cash")
{
//
}
}
}

这是我的 JavaScript,用于禁用单选按钮

$('input[type=radio]').change(function () {
$("#<%=loanTypeCheck.ClientID %>").find('input').prop('disabled', true);
});

UI 中一切正常,但我在后面的代码中的 LoanTypeCheck.SelectedValue 中得到空值。

最佳答案

您可以使用 :not(:checked) 选择器禁用未选中的单选按钮:

$('#<%= loanTypeCheck.ClientID %>').change(function () {
$(this).find('input[type=radio]:not(:checked)').prop('disabled', true);
});

保持选中的单选按钮处于启用状态将允许回发所选值。

关于javascript - 如果选择了其中之一,则禁用 Asp.net RadioButtonList 中的其他 RadioButton,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38684437/

32 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com