简体   繁体   English

验证程序插件jQuery中的errorPlacement问题

[英]Problem with errorPlacement in validator plugin jQuery

I am using the validator plugin of jQuery. 我正在使用jQuery的验证程序插件。 By default the error label is added below my form. 默认情况下,错误标签会添加到我的表单下方。 I want to add it above my form. 我想将其添加到表单上方。 So what I am doing is adding the code below in the validate(): 所以我正在做的是在validate()中添加以下代码:

errorPlacement: function (error, element) { 
    error.insertBefore('form#emailForm');
 }

The problem is that the error label now is added a lot of times above the form, in every click. 问题是,现在每次单击时,错误标签都会多次添加到表单上方。 So I have something like this: 所以我有这样的事情:

Enter valid email.Enter valid email.Enter valid email.

Does anyone know what's wrong with it? 有谁知道这是怎么回事?

Thanks in advance! 提前致谢!

If they're getting added lots of times all you have to do is remove them before they're added. 如果要多次添加它们,您要做的就是在添加它们之前将其删除。

errorPlacement: function (error, element) { 
    $('.error').remove();
    error.insertBefore('#emailForm');
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM