Javascript 如何免除要验证的元素?

Javascript 如何免除要验证的元素?,javascript,jquery,jquery-validate,Javascript,Jquery,Jquery Validate,我正在使用jquery的验证插件: 我想知道如何豁免要验证的字段?当前,表单中的所有字段都将自动选中 我不确定这是否有帮助,因为我想要豁免的元素显然没有包括在内: $("#contactForm").validate({ rules: { first_name:{required: true,charsonly:true,minlength: 1 }, last_name:{requ

我正在使用jquery的验证插件:

我想知道如何豁免要验证的字段?当前,表单中的所有字段都将自动选中

我不确定这是否有帮助,因为我想要豁免的元素显然没有包括在内:

  $("#contactForm").validate({
      rules: {
                        first_name:{required: true,charsonly:true,minlength: 1 },
                        last_name:{required:true,charsonly:true,minlength: 1 },
                        birthday:{required:true,min:1,max:31 },
                        birthmonth:"required",
                        birthyear:"required",
                        username: {required: true,minlength:1,maxlength:32,username:true,notChinese:true,noSpecial:true},
                        password1:{required:true,minlength: 5,maxlength: 10, alphaNum: true },
                        password2:{required:true,minlength: 5,maxlength: 10, alphaNum: true, equalTo: "#password1"},
                        currency:"required",
                        address:{required: true,noSpecial:true,minlength:2},
                        city:{required: true,noSpecial:true,minlength:2},
                        state:{noSpecial:true},
                        countrycode:"required",
                        zip:{required:true,zipTest:true},
                        email:{required:true,email:  true},
                        confirmemail:{required: true,equalTo:  "#email",email:true},
                        phone:{required: true,minlength:6,maxlength:20,phoneUS:true},
                        cellphone:{required: true,minlength:6,maxlength:20,phoneUS:true},
                        custom06:{acceptIM:true}

      } });
找到了。 我使用了忽略验证方法

这是密码

$("#myform").validate({
   ignore: ".ignore"
})

您正在使用某种服务器端技术吗?验证库需要设置规则,如果您严格使用JavaScriptjQuery执行此操作,那么它是手动的

更新:您可以删除具有以下内容的规则:

将以下各项放在阀体末端

$("selector").rules("remove");

它取决于类属性。见示例:

此字段为必填字段,电子邮件格式:不能为空

input class="required email"
此字段不是必填字段,电子邮件格式:可以为空

input class="email"
input class=""
此字段不是必需的,没有格式:可以为空

input class="email"
input class=""

您可以设置自己的消息:

$("#contactForm").validate({
      rules: {
         input1: required,
         input2: required,
         no-validation: required,
         input4: required,
      },
      messages: {
         no-validation: ''
      }
});

只需为您不想显示任何消息的字段输入一个空字符串。

否。我想要豁免的字段不在规则中[这意味着我没有添加任何字段,因为我不想验证它]。这不起作用,因为我已经将图像添加到插件附加到每个元素x或check的标签中。只是澄清一下。我想做的是删除这个插件自动附加这个代码,即使没有验证该元素。问题似乎源于使用一个全局规则函数,而不是设置每个元素的类。我仍然不知道如何解决这个问题。