【发布时间】:2017-06-15 17:56:04
【问题描述】:
我正在使用 ASP.NET 控件。在我的表单中,我有 4 个单选按钮。其中一个单选按钮组名称是 book,另一个是 card。如果没有单击任何单选按钮或仅单击其中一个组,我的目标是禁用下一个按钮。要启用下一个按钮,用户必须从书籍选项之一和卡片选项之一中进行选择。我怎样才能做到这一点?
视觉
ASP.NET - HTML
<div style="padding:30px; background-color:antiquewhite;">
<div style="background-color:aliceblue; width:190px; padding:10px;">
<asp:RadioButton ID="RadioPassBookYes" runat="server" Text="Book-Yes" GroupName="book"/>
<asp:RadioButton ID="RadioPassBookNo" runat="server" Text="Book-No" GroupName="book"/>
</div>
<br>
<div style="background-color:ActiveBorder; width:190px; padding:10px;">
<asp:RadioButton ID="RadioPassCardYes" runat="server" Text="Card-Yes" GroupName="card"/>
<asp:RadioButton ID="RadioPassCardNo" runat="server" Text="Card-No" GroupName="card"/>
</div>
<br>
<asp:Button ID="BtnNextRecentInfo" runat="server" Text="Next" disabled="disabled"/>
<asp:Button ID="btnCheck" runat="server" Text="Check" />
</div>
JS 脚本
<script type="text/javascript">
var isCheckedPassBookYes = $("#<%=RadioPassBookYes.ClientID%>").prop('checked');
var isCheckedPassBookNo = $("#<%=RadioPassBookNo.ClientID%>").prop('checked');
var isCheckedPassCardYes = $("#<%=RadioPassCardYes.ClientID%>").prop('checked');
var isCheckedPassCardNo = $("#<%=RadioPassCardNo.ClientID%>").prop('checked');
$("#<%=RadioPassBookYes.ClientID%>").click(function () {
});
$("#<%=RadioPassBookNo.ClientID%>").click(function () {
isCheckedPassBookNo = true
});
$("#<%=RadioPassCardYes.ClientID%>").click(function () {
});
$("#<%=RadioPassCardNo.ClientID%>").click(function () {
isCheckedPassCardNo = true
});
if (isCheckedPassBookYes === true) {
$("#<%=BtnNextRecentInfo.ClientID%>").attr("disabled", "disabled");
}
if (isCheckedPassBookNo === true) {
$("#<%=BtnNextRecentInfo.ClientID%>").removeAttr("disabled");
}
</script>
【问题讨论】:
标签: javascript c# jquery html asp.net