目前,我正在使用errorPlacement
为每个输入打印错误消息:
$('#my_form').validate({
errorPlacement: function(error, element) {
// Some code that print error below each inputs
},
...
然后,我尝试用showErrors
集中错误消息,如下所示:
showErrors: function(errorMap, errorList) {
// Some code that centralize each error for each input in one place
},
...
});
它工作正常,除了现在我只想集中我的表单的一些错误消息,而不是全部。就像仅将showErrors
用于我想要集中的输入,然后errorPlacement
用于其他输入。
就像只对我想要集中的输入使用
showErrors
,然后对其他输入使用errorPlacement
。
一个将永远超越另一个。
您必须对所有内容使用showErrors
,检查errorMap
和errorList
,并有条件地将每条消息放置在需要的位置。
你可以在 css 中使用 text-align:center; 属性。