0

我有一个带有 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();
  }
});

问题是在验证表单时,所有字段(用户名、密码、从和到)都得到相同errorIdentification的错误类,这是(用户名和密码)的第一个错误类

如何使用不同的错误类来实现这一点?

4

1 回答 1

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();
  }
});
于 2013-10-11T11:53:32.983 回答