JQueryValidation - 输入错误类名

发布于 2024-08-25 05:36:01 字数 326 浏览 3 评论 0原文

有没有办法使用 JQueryValidation 插件 设置输入 css 类错误。该 css 类与标签 css 错误类不同。

因为如果我设置: errorClass: "field-validation-error"

这将适用于标签输入。我希望输入具有“input-validation-error”css 类,标签具有“field-validation-error”css 类。

Is there a way with the JQueryValidation plugin to set the input css class error. This css class is different from the label css error class.

Because if I set : errorClass: "field-validation-error"

That will apply for label and input. I would like input to have "input-validation-error" css class and label to have "field-validation-error" css class.

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

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

发布评论

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

评论(1

豆芽 2024-09-01 05:36:01

我没有看到任何真正的理由支持错误元素和输入字段本身的不同类名。

只需使用CSS选择器

label.field-validation-error {
  ..whatever styling...
}
input.field-validation-error {
  ..whatever styling...
}

这种方式都应用了相同的css类,但获得了不同的样式


但是如果你真的认为你需要这个,那么你可以使用highlightunhighlight选项验证插件并将它们与函数连接起来。然后,它们可以将所需的样式应用于元素和错误标签。在 文档 中,甚至是一个很好的示例,您应该可以轻松地根据您的需要进行修改

I don't see any real reason to support different class names for the error element and the input field itself.

Just use CSS-selectors

label.field-validation-error {
  ..whatever styling...
}
input.field-validation-error {
  ..whatever styling...
}

This way both have the same css-class applied but get different styling


But if you really think you need this than you can use the highlight and unhighlight options of the validation plugin and wire them up with functions. These can then apply the wanted styles to the element and the error label. In the documentation is even a nice example of this which you should be easily able to modify to your needs

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