jQuery 验证和分组 - 如何避免 errorPlacement 使用?
当前 groups
用法的示例表明 errorPlacement
应该被定义,其中字段名称是硬编码的:
$("#myform").validate({
groups: {
username: "fname lname"
},
errorPlacement: function(error, element) {
if (element.attr("name") == "fname"
|| element.attr("name") == "lname" )
error.insertAfter("#lastname");
else
error.insertAfter(element);
},
debug:true
})
有什么方法可以摆脱这个带有字段名称的 errorPlacement
吗?错误消息应始终位于组中最后一个元素之后。
Current example of groups
usage says that errorPlacement
should be defined, where names of fields are hard coded:
$("#myform").validate({
groups: {
username: "fname lname"
},
errorPlacement: function(error, element) {
if (element.attr("name") == "fname"
|| element.attr("name") == "lname" )
error.insertAfter("#lastname");
else
error.insertAfter(element);
},
debug:true
})
Is there any way to get rid of this errorPlacement
with field names? The error message should be always places after last element in the group.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我认为您将不得不使用
errorPlacement
,但您可以使用一些技巧,让错误每次都出现在组之间一致的位置:基本上,访问
groups
code> 您定义的对象并找到每个组中的最后一个字段。将错误附加到该字段之后。示例: http://jsbin.com/acenic/
I think you're going to have to use
errorPlacement
, but you can pull out a few tricks to get the error in a consistent place among groups every time:Basically, access the
groups
object that you've defined and find the last field in every group. Attach the error after that field.Example: http://jsbin.com/acenic/