jQuery的使用ASP.NET的WebForms - 禁用文本框 [英] jQuery with ASP.NET WebForms - disabling textboxes

查看:90
本文介绍了jQuery的使用ASP.NET的WebForms - 禁用文本框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

另一个jQuery的noob问题 - 我在做什么错了?

Another jQuery noob question - what am I doing wrong??

我有ASP.NET 3.5 Web表单看起来像这样一些渲染的HTML标记:

I have some HTML markup rendered by ASP.NET 3.5 webforms which looks like this:

<input id="ctl01_cphContent_pnlBasicInfo_chkRC" 
       type="checkbox" name="ctl01$cphContent$pnlBasicInfo$chkRC" />
<label for="ctl01_cphContent_cntPromos_pnlBasicInfo_chkRC">Recurrent Charges</label>

<span id="ctl01_cphContent_cntPromos_pnlBasicInfo_lblPromoValidFor" 
      class="rcPromo">Validity:</span>

<span class="rcPromo">
   <input id="ctl01_cphContent_pnlBasicInfo_rbnDiscountValidFor" 
          type="radio" name="ctl01$cphContent$pnlBasicInfo$discountValidFor" 
          value="rbnDiscountValidFor" checked="checked" />
   <label for="ctl01_cphContent_cntPromos_pnlBasicInfo_rbnDiscountValidFor">valid for</label>
</span>
<span class="rcPromo">
   <input id="ctl01_cphContent_pnlBasicInfo_rbnDiscountValidUntil" 
          type="radio" name="ctl01$cphContent$pnlBasicInfo$discountValidFor" 
          value="rbnDiscountValidUntil" />
   <label for="ctl01_cphContent_cntPromos_pnlBasicInfo_rbnDiscountValidUntil">valid until</label>
</span>

<input name="ctl01$cphContent$pnlBasicInfo$txtDiscountMonths" type="text"
       id="ctl01_cphContent_pnlBasicInfo_txtDiscountMonths" 
       class="textbox" class="rcPromo" originalValue="" style="width:30px;" />
<span id="ctl01_cphContent_cntPromos_pnlBasicInfo_lblMonths" class="rcPromo"></span>

<input name="ctl01$cphContent$pnlBasicInfo$txtDiscountUntil" type="text" 
       id="ctl01_cphContent_pnlBasicInfo_txtDiscountUntil" 
       class="textbox" class="rcPromo" originalValue="" style="width:150px;" />


  • 我已经选中的chkRC,我想陷阱和使用,启用/禁用其他UI控件

  • 我有很多标签,输入(类型=无线电)和输入(类型=文本)的UI控件。这些都标有rcPromo虚拟CSS类

  • 我有一个名为文本框,为正常的文本框和textboxDisabled为文本框的禁用状态的CSS类,在一个外部引用CSS文件,在服务器端code使用时工作正常(,即是)

  • 我试图在jQuery来做到这一点的是:当chkRC复选框被禁用,我想禁用所有相关的UI控件

    What I'm trying to accomplish in jQuery is this: when the "chkRC" checkbox is disabled, I want to disable all relevant UI controls.

    我的jQuery的是这样的:

    My jQuery looks like this:

        $(document).ready(function() {
            $("#<%= chkRC.ClientID %>").click(function() {
                $('.rcPromo > :label').toggleClass('dimmed');
    
                if (this.checked) {
                    $('.rcPromo').removeAttr('disabled');
                    $('.rcPromo .textboxDisabled').addClass('textbox').removeClass('textboxDisabled');
                }
                else {
                    $('.rcPromo > :input').removeAttr('checked');
                    $('.rcPromo .textbox').addClass('textboxDisabled').removeClass('textbox');
                    $('.rcPromo').attr('disabled', true);
                }
            });
        });
    

    它工作正常的标签和单选按钮 - 但我不能让它使用文本框的工作 - 他们只是待在各地一样,没有什么变化(他们没有得到禁止,他们不改变他们的出现,表明他们是残疾人,无论是)。

    It works fine for the labels and the radiobuttons - but I just can't get it to work with the textboxes - they just stay the same all around, nothing changes (they don't get disabled and they don't change their appearance to indicate that they're disabled, either).

    我不明白这一点 - 我看到几个(几比样品更多)文本框,这是&LT;输入类型=文本&GT; 在HTML中,他们确实有类=rcPromo类=文本框对他们的 - 那么,为什么没有jQuery的查找和更新这些?

    I don't understand this - I do see several (a few more than in the sample) textboxes, which are <input type="text"> in HTML, and they do have the class="rcPromo" and class="textbox" on them - so why doesn't jQuery find and update those?

    任何想法?

    马克

    推荐答案

    我想不出办法来补充从皮肤文件分配到控制CSS类名(凤凰是正确的,类名需要在相同的属性添加)。

    I can't think of a way to augment the css class names that are assigned to controls from the skin file (phoenix is correct, the class names need to be added in the same attribute).

    我虽然可以想到几个解决方法:

    I can think of a few workarounds though:

    - >你可以用所有的文本框要在一个给定类的div禁用:

    --> You can wrap all the textboxes you want disabled in a div with a given class:

    <div class="disable_textbox"><asp:textbox id="".../></div>
    

    ,然后通过选择禁用它们:

    and then disable them by selecting:

    $('.disable_textbox input').attr('disabled', true);
    

    - >您可以在文本框的ID字符串您希望禁用:

    --> You can include character strings in the ID of the textboxes you want disabled:

    <asp:textbox id="txtDiscountUntil_DisableMe" ... />
    

    ,然后禁用它们像这样:

    and then disable them like so:

    $("input[id*='DisableMe']").attr('disabled', true);
    

    - >您可以自定义属性添加到您的文本框:

    --> You can add a custom attribute to your textbox:

    txtDiscountUntil.Attributes.Add("disableme", "true");
    

    ,然后禁用它们像这样:

    and then disable them like so:

    $("input[disableme='true']").attr('disabled', true);
    

    这篇关于jQuery的使用ASP.NET的WebForms - 禁用文本框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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