具有不同错误类的单个ID

时间:2013-10-11 11:44:39

标签: jquery css

我有一个ID为form_select)的表单,其中包含2个错误类(errorIdentificationerrorIdentification1)。

$('#form_select').validate({
  rules: {
    'user_name' : {
       required: true
       },
    'password'   : {
       required: true
    }
  },
  messages: {
    'user_name' : {
       required: 'From date is required!'
      },
    'password'   : {
       required: 'To date is required!'
      }
  },
  errorClass: **'errorIdentification'**,
  errorPlacement: function(err, element) {
  err.insertBefore(element);
  },
  submitHandler: function(form) {

  form.submit();
  }
});


$('#form_select').validate({
  rules: {
    'from' : {
       required: true
       },
    'to'   : {
       required: true
    }
  },
  messages: {
    'from' : {
       required: 'From date is required!'
      },
    'to'   : {
       required: 'To date is required!'
      }
  },
  errorClass: **'errorIdentification1'**,
  errorPlacement: function(err, element) {
  err.insertBefore(element);
  },
  submitHandler: function(form) {

  form.submit();
  }
});

问题在于验证表单,所有字段(用户名,密码,from和to)都获得相同的errorClass errorIdentification,这是(用户名和密码)的第一个错误类

如何使用不同的错误类实现此功能?

1 个答案:

答案 0 :(得分:0)

更改您的第二个表单脚本,如;

$('#form_select').validate({
  rules: {
    'from' : {
       required: true
       },
    'to'   : {
       required: true
    }
  },
  messages: {
    'from' : {
       required: 'From date is required!'
      },
    'to'   : {
       required: 'To date is required!'
      }
  },
  errorClass: **'errorIdentification1'**,
  errorPlacement: function(err, element) {
  err.insertBefore(element);
  },
  submitHandler: function(form) {

  form.submit();
  }
});