文本框必须等于false

时间:2010-12-28 10:45:33

标签: c# javascript

如何在此代码中使所需的文本框等于false

$(document).ready(function () {
        $("#<%= chkSpecialIntegration.ClientID %>").click(function () {
            if (this.checked) {
               $("#<%= ddlTypeSpecialIntegration.ClientID %>").show();

                document.getElementById('<%=txtTotalScoreDebit.ClientID %>').Required = false; }
else{
 $("#<%= ddlTypeSpecialIntegration.ClientID %>").hide();
 document.getElementById('<%=txtTotalScoreDebit.ClientID %>').Required = true;
}

        });
    });

2 个答案:

答案 0 :(得分:1)

它是.required,小写,您可以进一步简化代码,因为您正在处理布尔值,如下所示:

$(document).ready(function () {
  $("#<%= chkSpecialIntegration.ClientID %>").click(function () {
    $("#<%= ddlTypeSpecialIntegration.ClientID %>").toggle(this.checked);
    document.getElementById('<%=txtTotalScoreDebit.ClientID %>').required = !this.checked;
  });
});

You can test it out here

答案 1 :(得分:0)

您在谈论this吗?

$("#myform").validate({
  rules: {
    field: "required"
  }
});