如何显示 jQuery 验证中的错误?
我们是否有任何函数可以在验证表单时返回所有错误消息?
我尝试使用 defaultshowerros() 函数,但它返回当前正在验证的元素的错误消息。如何获取整个表单的所有错误信息?
Do we have any function which returns all the error messages while validating a form?
I have tried using the defaultshowerros() function but it returns the error message for the element it is currently validating. How can I get all the error messages of the whole form?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
如果您存储对验证器的引用,例如:
您可以随时调用
.errors()
或.invalidElements()
,例如:如果您'不是真的在错误之后,只是希望它们出现在一个地方,请使用内置的
errorLabelContainer
和wrapper
选项,例如:并引用:
并且您的错误将全部显示在该列表中,如果存在,该列表也会自动显示/隐藏/没有任何错误。
If you store a reference to the validator, for example:
You can call
.errors()
or.invalidElements()
at any time on it, for example:If you're not really after the errors and just want them to appear in once place, use the built-in
errorLabelContainer
andwrapper
options, for example:And reference that:
And your errors would appear all in that list, which is also automatically shown/hidden if there are/aren't any errors.
验证插件应在错误所在字段旁边显示错误。您的输入框使用 id 吗?如果是这样,也请使用名称,并在规则和消息中为 jquery 提供名称属性的值。希望这有帮助。
The validation plugin should show an error beside the field where the error is. Are you using id's for your input boxes? If so use a name as well and give jquery the value of the name attribute in your rules and messages. Hope this helps.
虽然迟到了,但我发现您还可以使用
invalidHandler()
函数实例化validate()
对象:validation
变量包含一个带有表单项及其错误消息的变量invalid
(对象)。Late to the party, but I found you can also instantiate the
validate()
object with ainvalidHandler()
function:The
validation
variable contains a variableinvalid
(object) with form items and their error messages.