Jquery 验证插件问题

发布于 2024-09-17 18:11:22 字数 699 浏览 1 评论 0原文

我正在尝试使用 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

伊面 2024-09-24 18:11:22

有一个 errorContainer 选项,使用它像这样:

$("#myform").validate({
    errorContainer: "div.container",
    errorPlacement: function(error, element) {
            error.appendTo("div.container");
    }
});

如果有/没有任何错误,则该选项的选择器将分别显示/隐藏。

There's an errorContainer option for this, use it like this:

$("#myform").validate({
    errorContainer: "div.container",
    errorPlacement: function(error, element) {
            error.appendTo("div.container");
    }
});

The selector given to this option will be shown/hidden if there are/aren't any errors, respectively.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文