特定规则中特定错误的JQuery验证程序特定位置(errorPlacement不会重新定位错误)

时间:2016-08-25 10:54:45

标签: javascript jquery jquery-validate

我希望特定字段上的特定错误具有不同的位置。 我尝试的是下一个,但errorPlacement仅在第一次正确定位错误标签并保持该位置,在修复验证错误时使其内容为空。 (因此,只有先前从dom手动删除时才会重新定位标签错误)

errorPlacement: function(error, element) {
  if (error.text() == 'specific error from a specific rule') {
    ///position error in the bottom off the form
  }
  else {
    //position error in the default place as for all field errors
  }
},

1 个答案:

答案 0 :(得分:0)

  

...仅在第一次正确定位错误标签并保持该位置......

是的,这是因为默认行为是插入错误消息元素并为所有后续错误切换它。这就是插件的设计方式。