Jquery 验证插件问题
我正在尝试使用 jquery 验证插件,但我似乎无法让它在一个上工作 特定的方面。
我有这种情况,我的表单空间有限,因此验证插件生成的标签错误 如果存在验证错误,则无法看到
所以我所做的是,我在表单下方创建了一个容器作为错误的容器。该容器的初始显示为无 (display:none
)
这是我的标记,以便您可以将其可视化。
<form id="myform">
</form>
<div id="container">
<h4>There is an error in your form entry. Kindly correct please.</h4>
</div>
我在网上发现了有关错误放置的验证插件的内部方法,因此我使用了它。
$("#myform").validate({
errorPlacement: function(error, element) {
error.appendTo("div.container");
}
});
一切都很好,当发生错误时,它会很好地附加到我的容器上。我的问题是 更正错误后,标签错误被隐藏,但我的容器 div 仍然显示。
我该怎么做才能在更正错误后,容器 div 也被隐藏。谢谢。
I am trying my way around on using the jquery validate plugin but I cant seem to make it work on one
particular aspect.
I have this scenario, my form has limited space so the label error generated by the validate plugin
cannot be seen if ever there is a validation error
So what I did is, I created a container below my form to serve as container for the error. Initial display of this container is none (display:none
)
Here's my markup so that you can visualize it.
<form id="myform">
</form>
<div id="container">
<h4>There is an error in your form entry. Kindly correct please.</h4>
</div>
I found out on the net regarding an internal method of the validate plugin regarding the errorplacement so I made use of it.
$("#myform").validate({
errorPlacement: function(error, element) {
error.appendTo("div.container");
}
});
All is well when an error has occured it gets appended nicely on my container. My problem is
upon correcting the error, the label error gets hidden but my container div is still shown.
What can I do so that after you have corrected the error, the container div gets hidden also. Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
有一个
errorContainer
选项,使用它像这样:如果有/没有任何错误,则该选项的选择器将分别显示/隐藏。
There's an
errorContainer
option for this, use it like this:The selector given to this option will be shown/hidden if there are/aren't any errors, respectively.