简体   繁体   English

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

[英]using jquery how do I validate individual elements and show the relevant error message in the Validation Summary

I have a form that has seperate divs that are shown and hidden as the user progresses down the page. 我有一个表单,其中包含单独的div,这些div在用户向下浏览页面时显示和隐藏。

The submit is only down at the bottom of the page. 提交仅在页面底部。

Each div has a button that calls a javascript function. 每个div都有一个调用javascript函数的按钮。 In the function I want to only validate the elements within that div. 在函数中,我只想验证该div中的元素。

I have tried the validate.element("#txtUserName") and that does validate the specific elements, but then does not show the validation summary. 我已经尝试了validate.element(“#txtUserName”)并验证了特定元素,但随后未显示验证摘要。

I have also tried $("#frm").validate().form(), but that validated everything on the form - so divs the user hadn't even reached yet. 我也尝试过$(“#frm”)。validate()。form(),但这可以验证表单上的所有内容-因此div用户甚至都没有达到。

Thanks. 谢谢。

Use $(element).validate(options); 使用$(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. 请参阅此页面以获取详细的文档,包括示例。

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

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