Jquery表单验证:显示网页特定部分中的所有错误


Jquery Form Validation: Display all errors in a specific section of the webpage

我正在使用JQuery的验证插件来验证HTML表单。http://docs.jquery.com/Plugins/Validation

默认情况下,所有验证错误都位于输入旁边。是否可以在页面顶部显示所有错误的列表,以及我使用的代码?

根据您可以为该插件提供的选项(请参阅http://docs.jquery.com/Plugins/Validation/validate#options),您可以指定errorLabelContainererrorContainer选项,在这两个选项中,它将把错误消息分组到一个或多个容器中。

现场取样:

<ul id="messageBox"></ul>

 

$("#myform").validate({
   errorLabelContainer: "#messageBox",
   wrapper: "li",
   submitHandler: function() { alert("Submitted!") }
})