如何在按钮单击时禁用单选按钮? [英] How to disable radio button on button click?

查看:91
本文介绍了如何在按钮单击时禁用单选按钮?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的项目中有单选按钮,如果选择了4个属性列表中的2个选项之一,则应该禁用它们。这是我的代码:



I have radio buttons in my project which should get disabled if one of the 2 options from a list of 4 attributes is selected. This is my code:

<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:





I used javascript for this purpose:

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;
    }
}





在我的后端代码:





At my backend code:

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();
    }

}





现在问题是我的网站上有两个按钮。每当我点击这些按钮时,即使我选择了维护或报告,单选按钮也会被激活。如何禁用它?



这是在我的页面加载事件:





Now the problem is there are two buttons on my website. Whenever I click those buttons, the radio buttons get activated even when I have selected Maintenance or Reporting . How do I disable that?

This is on my page load event:

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);");
}

推荐答案

在您的代码中,您有以下内容..........





in your code where you have the following..........


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();
    }

}







不应该...... ...........






Shouldnt that be.............

protected void drpLType_SelectedIndexChanged(object sender, EventArgs e)
{
    if (drpLType.SelectedValue == "1")
    {
        rdoMeapSupport.Enabled = true;
    }

    if (drpLType.SelectedValue == "2")
    {
        rdoMeapSupport.SelectedValue = null;
        rdoMeapSupport.Enabled = true;
    }

    if ((drpLType.SelectedValue == "3") || (drpLType.SelectedValue == "4"))
    {
        rdoMeapSupport.Enabled = false;
        rdoMeapSupport.ClearSelection();
    }

}







原因是你有明确定义的VALUE =1值=2等




The reason for this is you have CLEARLY defined VALUE="1" value="2" etc


这篇关于如何在按钮单击时禁用单选按钮?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆