如何使用jquery验证插件查看顶部标签的特定消息?

发布于 2024-10-01 01:55:48 字数 153 浏览 0 评论 0原文

我正在使用 jquery 验证插件在顶部而不是标签旁边显示错误消息。比如说,我有地址、城市、邮政编码...如果用户不输入任何内容,我必须在 div 顶部显示错误消息,例如“请输入有效地址”、“请输入有效城市”等。 。 我如何覆盖插件的默认行为......任何帮助将不胜感激...... 谢谢!

I am using jquery validation plugin to display error message in the top instead instead of beside the labels. say, i have address , city, zip code ....if user don't enter anything i have to display the error message at top in a div like " please enter valid address" , "please enter valid city" etc...
how can I override the default behavior of the plugin .....any help will be appreciated ...
thanks!

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

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

发布评论

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

评论(1

做个ˇ局外人 2024-10-08 01:55:48

您可以使用 errorLabelContainerwrapper 选项 为此:

$("form").validate({
  errorLabelContainer: "#someElementUpTop", //a <ul> element for example
  wrapper: "li" //display them in a list
});

errorLabelContainer 确定添加错误元素的位置,wrapper 确定它们所包装的内容。在本例中 #someElementUpTop 是一个

    ,用于将

  • 包装标签附加到...因此单击仍会转到页面中存在验证错误的正确元素。如果您需要在此之上的另一个元素,例如在存在/不存在错误时适当隐藏和显示的
    ,请添加一个errorContainer:“ #someDiv" 选项。

You can use errorLabelContainer and wrapper options for this:

$("form").validate({
  errorLabelContainer: "#someElementUpTop", //a <ul> element for example
  wrapper: "li" //display them in a list
});

errorLabelContainer determines where the error elements are added, wrapper determines what they're wrapped in. In this case #someElementUpTop is a <ul> to append the <li> wrapped labels to...so clicking still goes to the correct element in the page that has the validation error. If you need another element above this, say a <div> that hides and shows appropriately when there are/aren't errors, add a errorContainer: "#someDiv" option as well.

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