使用 jquery 如何验证各个元素并在验证摘要中显示相关错误消息

发布于 2024-12-04 14:19:36 字数 286 浏览 6 评论 0原文

我有一个表单,其中有单独的 div,当用户向下浏览页面时,这些 div 会显示和隐藏。

提交仅在页面底部。

每个 div 都有一个调用 javascript 函数的按钮。 在函数中,我只想验证该 div 中的元素。

我尝试过 validate.element("#txtUserName") ,它确实验证了特定元素,但随后不显示验证摘要。

我也尝试过 $("#frm").validate().form(),但是验证了表单上的所有内容 - 所以用户甚至还没有到达div。

谢谢。

I have a form that has seperate divs that are shown and hidden as the user progresses down the page.

The submit is only down at the bottom of the page.

Each div has a button that calls a javascript function.
In the function I want to only validate the elements within that div.

I have tried the validate.element("#txtUserName") and that does validate the specific elements, but then does not show the validation summary.

I have also tried $("#frm").validate().form(), but that validated everything on the form - so divs the user hadn't even reached yet.

Thanks.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(1

许仙没带伞 2024-12-11 14:19:36

使用 $(element).validate(options);,这样:

function validateCallback(){
    //do something
}
$("#txtUserName").validate({onValidate:validateCallback})

参见 this页 进行简要概述;有关详细文档(包括示例),请参阅此页面

Use $(element).validate(options);, in this way:

function validateCallback(){
    //do something
}
$("#txtUserName").validate({onValidate:validateCallback})

See this page for a small overview; See this page for a detailled documentation, including examples.

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