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

发布于 2025-01-02 23:10:05 字数 2511 浏览 0 评论 0原文

我有这样的代码:

 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>

我需要隐藏或显示一些带有条件单选按钮的链接按钮(在本例中单选按钮radbutton telerik)。

这段代码不起作用。

I have code like this:

 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>

I need hide or display some linkbutton with condition radiobutton (in this case radiobutton radbutton telerik).

This code not work.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

昨迟人 2025-01-09 23:10:05

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

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

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

By the looks of you "$find(...)" it seems like you're trying to use jQuery? If so, change the code of the variable declarations as follows:

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

You need to tell the jQuery selector whether you are looking for an element type $("element"), element ID $("#element") or element CSS class $(".element"). Your variable declaration assumed you are looking for an element TYPE (i.e. a tag of type "<%= rdMonthlyInstallment.ClientID %>"), which is incorrect. You should be looking for an element ID.

沦落红尘 2025-01-09 23:10:05

我认为一个问题是你总是将 display = "none" 设置为 btRecalculateByLoan、btCalculateByInstallment 和 btRecalculateByInstallment

I think a problem is that you always set display = "none" to the btRecalculateByLoan, btCalculateByInstallment and btRecalculateByInstallment

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文