如果选择了 4 个属性列表中的 2 个选项之一,我的项目中有单选按钮应该被禁用。这是我的代码:
<asp:DropDownList ID="drpLType" runat="server" CssClass="drp">
<asp:ListItem Value="0" Selected="True">Professional</asp:ListItem>
<asp:ListItem Value="1">Enterprise</asp:ListItem>
<asp:ListItem Value="2">Maintanence</asp:ListItem>
<asp:ListItem Value="3">Reporting</asp:ListItem>
</asp:DropDownList>
我为此目的使用了javascript:
function funMeapSupportValidate(val)
{
switch(val)
{
case "0" :
document.getElementById('<%=this.rdoMeapSupport.ClientID%>').disabled = false;
break;
case "1" :
document.getElementById('<%=this.rdoMeapSupport.ClientID%>').disabled = false;
break;
case "2" :
document.getElementById('<%=this.rdoMeapSupport.ClientID%>').check = false;
document.getElementById('<%=this.rdoMeapSupport.ClientID%>').disabled = true;
break;
case "3" :
document.getElementById('<%=this.rdoMeapSupport.ClientID%>').check = false;
document.getElementById('<%=this.rdoMeapSupport.ClientID%>').disabled = true;
break;
default:
break;
}
}
在我的后端代码:
protected void drpLType_SelectedIndexChanged(object sender, EventArgs e)
{
if (drpLType.SelectedValue == "Professional")
{
rdoMeapSupport.Enabled = true;
}
if (drpLType.SelectedValue == "Enterprise")
{
rdoMeapSupport.SelectedValue = null;
rdoMeapSupport.Enabled = true;
}
if ((drpLType.SelectedValue == "Maintanence") || (drpLType.SelectedValue == "Reporting"))
{
rdoMeapSupport.Enabled = false;
rdoMeapSupport.ClearSelection();
}
}
现在的问题是我的网站上有两个按钮。每当我单击这些按钮时,即使我选择了Maintenance
或,单选按钮也会被激活Reporting
。我该如何禁用它?
在我的页面加载:
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
Tab1.CssClass = "Clicked";
MainView.ActiveViewIndex = 0;
if (drpLType.SelectedValue == "Professional")
{
rdoMeapSupport.Enabled = true;
rdoMeapSupport.SelectedValue = "Yes";
}
drpLType_SelectedIndexChanged();
}
drpLType.Attributes.Add("onchange", "javascript:funMeapSupportValidate(this.value);");
}