如何在asp.net中使用javascript禁用链接按钮或隐藏链接按钮

时间:2012-02-07 08:01:57

标签: javascript asp.net javascript-events

我有这样的代码

 function rdLoanChecked() {

            var isCheckedInstallment = $find("<%= rdMonthlyInstallment.ClientID %>").get_checked();
            var isCheckedLoanAmount = $find("<%= rdLoanAmount.ClientID %>").get_checked();

            if (isCheckedLoanAmount) {

                document.getElementById('<%= btRecalculateByLoan.ClientID %>').style.display = "none";
                document.getElementById('<%= btCalculateByInstallment.ClientID %>').style.display = "none";
                document.getElementById('<%= btRecalculateByInstallment.ClientID %>').style.display = "none";
                document.getElementById('<%= btnext.ClientID %>').style.display = "none";
                document.getElementById('<%= btCalculateByLoan.ClientID %>').style.display = "inline";

            }
            else if (isCheckedInstallment) {

                document.getElementById('<%= btRecalculateByLoan.ClientID %>').style.display = "none";
                document.getElementById('<%= btCalculateByInstallment.ClientID %>').style.display = "none";
                document.getElementById('<%= btRecalculateByInstallment.ClientID %>').style.display = "none";
                document.getElementById('<%= btnext.ClientID %>').style.display = "inline";
                document.getElementById('<%= btCalculateByLoan.ClientID %>').style.display = "none";
            }



<td width="5%" style="vertical-align: middle;">
  <telerik:RadButton ID="rdLoanAmount" runat="server" ButtonType="ToggleButton" Text=""
   OnClientCheckedChanged="rdLoanChecked" CssClass="rdLoanAmount" 
   ToggleType="Radio" GroupName="rdCalculationBy" BorderStyle="None">
                        </telerik:RadButton>
</td>
<td style="vertical-align: middle;">
   <cc1:LocalizedLabel ID="lblLoanAmount" runat="server" Key="lblLoanAmount"></cc1:LocalizedLabel>
</td>
<td style="vertical-align: top;" width="5%">
   <telerik:RadButton ID="rdMonthlyInstallment" runat="server" ButtonType="ToggleButton"
   OnClientCheckedChanged="rdLoanChecked" CssClass="rdMonthlyInstallment" 
   Text="" ToggleType="Radio" GroupName="rdCalculationBy" BorderStyle="None">
                        </telerik:RadButton>
</td>



我需要隐藏或显示一些带条件radiobutton的链接按钮(在这种情况下是radiobutton radbutton telerik)
这段代码不起作用
在此先感谢

2 个答案:

答案 0 :(得分:0)

你看起来“$ find(...)”看起来你似乎在尝试使用jQuery?如果是这样,请按如下所示更改变量声明的代码:

var isCheckedInstallment = $("#<%= rdMonthlyInstallment.ClientID %>").is(":checked"); 
var isCheckedLoanAmount = $("#<%= rdLoanAmount.ClientID %>").is(":checked");

您需要告诉jQuery选择器您是在寻找元素类型$("element"),元素ID $("#element")还是元素CSS类$(".element")。您的变量声明假设您正在寻找一个元素TYPE(即类型为“<%= rdMonthlyInstallment.ClientID %>”的标记),这是不正确的。您应该寻找元素ID。

答案 1 :(得分:0)

我认为问题在于你总是将display =“none”设置为btRecalculateByLoan,btCalculateByInstallment和btRecalculateByInstallment