简体   繁体   English

在Jquery中禁用验证控件?

[英]Disable a validation control in Jquery?

I have asp.net web form with lot of .net controls. 我有很多.net控件的asp.net Web表单。 where few of the controls are disabled depending on the input of another controls. 其中,根据其他控件的输入,很少有控件被禁用。 All of the controls are required so i have to check for required validation as well. 所有控件都是必需的,因此我也必须检查所需的验证。 I can disable the control using jquery but i am not able to disable the validation control. 我可以使用jquery禁用该控件,但无法禁用验证控件。

Here is my code.. any better way of doing this will be very appreciable. 这是我的代码。执行此操作的任何更好方法将是非常可观的。

  <script>

       $('#<%=rdb_one.ClientID%> input:radio').click(function () {

     var currentIdone = 'Humans';
     var currentId = $(this).val();
     if (currentId != currentIdone) {
         $('#<%=rdb_two.ClientID%> input').attr('checked', false);
         $('#<%=rdb_two.ClientID%> input').attr('disabled', 'disabled');


     }
     else {

         $('#<%=lstExposureValue.ClientID%> input').removeAttr('disabled');



     }

 });

 </script>

 <asp:RadioButtonList CssClass="Required"  ID="rdb_one" runat="server" OnSelectedIndexChanged="rdb_studysubj_SelectedIndexChanged">
          <asp:ListItem Value="Humans">Humans</asp:ListItem>
          <asp:ListItem Value="Non-Human primates">Non-Human primates</asp:ListItem>
          <asp:ListItem Value="Rodents">Rodents</asp:ListItem>
          <asp:ListItem Value="Others">Others</asp:ListItem>
          </asp:RadioButtonList>
      <br/>
      <br/>
         <asp:RadioButtonList CssClass="Required" ID="rdb_two" runat="server"  OnSelectedIndexChanged="rdb_study_popul_SelectedIndexChanged">
           <asp:ListItem>Individuals</asp:ListItem>
           <asp:ListItem>Population</asp:ListItem>
           </asp:RadioButtonList>
           <asp:RequiredFieldValidator ID="vald_one" Display="None" ErrorMessage="Study Population is Required" runat="server" ControlToValidate="rdb_two"></asp:RequiredFieldValidator> 

Here i disable the control "rdb_two" depending on the value from "rdb_one" but i am not able to disable the validation controls for "rdb_two" any ideas. 在这里,我禁用该控件“rdb_two”根据来自“rdb_one”的价值,但我不能够禁用验证控件“rdb_two”任何想法。 i have this function repeatedly used over all the controls with in the same page. 我在同一页面的所有控件上重复使用了此功能。

您可以使用ValidatorEnable函数为例

ValidatorEnable(document.getElementById($(this).attr('id')), false);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM